1
Mithrandir
Need Javascript help

I'm not much of a javascript coder, but found it to be necessary in order to complete the new XoopsFormSelectUser class in XOOPS 2.2

What I am trying to do
I have a lookup window (popup) where one can search for users and with a checkbox select the relevant user(s) from the search result.

I want those selected users to be added to the form in the calling page - i.e. a hidden field with the uid, a disabled text field with the user's name and a link to remove the user again.

I'm having some trouble figuring out how to capture the selected checkboxes and create form elements in the form in the calling window.

Some code
var usercount '.$count.';

function 
addUser(userInfos) {
    var 
formDiv window.opener.xoopsGetElementById("'.$_REQUEST['target'].'"+"div");
    
    for (
i=0i<userInfos.lengthi++) {
        var 
uinfo userInfos[i].split("^");
        
        var 
nameDom window.opener.createElement(input);
        
nameDom.setAtribute("name""'.$_REQUEST['target'].'text");
        
nameDom.setAttribute("id""'.$_REQUEST['target'].'"+"text"+usercount");
        nameDom.setAttribute("
type","text");
        nameDom.setAttribute("
size","15");
           nameDom.setAttribute("
maxlength","255");
        nameDom.setAttribute("
value",uinfo[1]);
        
        formDiv.appendChild(nameDom);
    }
    window.close();
    return;
}

function getSelectedCheckboxValues(checkbox) {
    if (checkbox.length) {
        var returnvalues = array();
        for (var i = 0; i < checkbox.length; i++) {
            if (checkbox[i].checked) {
                returnvalues[] = chekbox[i].value;
            }
        }
        return returnvalues;
    } else {
        return checkbox.value;
    }
}


//In the lookup form's onSubmit:
addUser(getSelectedCheckboxValues(frmResults.chooseUser));

//frmResults is the ID of the form
//chooseUser is the ID of the checkbox


Anybody able to help?
"When you can flatten entire cities at a whim, a tendency towards quiet reflection and seeing-things-from-the-other-fellow's-point-of-view is seldom necessary."

Cusix Software

2
davidthomas1
Re: Need Javascript help

Wow, this is totally out of my league but...

A couple of general ideas :

1)Cookies: I know you can pass values from page to page in javascript using cookies... would that be of any help?

2)Frames: I know you can refer to the parent frame, maybe set properties etc using frames. Would it help to use frames instead of a pop-up window?

Sorry for my limited suggestions. Maybe just a little food for thought.

kind regards,

D.
みんなちがってみんないい。

XOOPS 2.0.13.2

3
Mithrandir
Re: Need Javascript help

1) Seems a little cumbersome, I'm afraid

2) Frames or other windows - it's more or less the same, when it comes to javascript.

And it is not so much the communication between the windows that is troubleshome, it is how to capture the selected checkbox values correctly and adding the form element dynamically to the form.
"When you can flatten entire cities at a whim, a tendency towards quiet reflection and seeing-things-from-the-other-fellow's-point-of-view is seldom necessary."

Cusix Software

4
jlm69
Re: Need Javascript help
  • 2005/6/25 16:55

  • jlm69

  • Module Developer

  • Posts: 719

  • Since: 2002/7/19


I don't know if this will help but you have a typo, in the function

function getSelectedCheckboxValues(checkbox)

you have

returnvalues[] = chekbox[i].value;

it should probably be

returnvalues[] = checkbox[i].value;

hope that helps

5
Mithrandir
Re: Need Javascript help

Thanks. Didn't make it better, though.

If I replace the onsubmit code with alert("something"); it works, but if I put the call to getCheckboxValues back and write alert("something"); as the first line in the function, nothing happens - except that the form submits to the same page.

I'm getting no javascript errors in my javascript console, either.
"When you can flatten entire cities at a whim, a tendency towards quiet reflection and seeing-things-from-the-other-fellow's-point-of-view is seldom necessary."

Cusix Software

Login

Who's Online

103 user(s) are online (54 user(s) are browsing Support Forums)


Members: 0


Guests: 103


more...

Donat-O-Meter

Stats
Goal: $100.00
Due Date: May 31
Gross Amount: $0.00
Net Balance: $0.00
Left to go: $100.00
Make donations with PayPal!

Latest GitHub Commits