Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsGeneralPHPASPPerlColdFusionFlashHTML, CSS, ScriptsBrowsers

Webmaster Forum / HTML, CSS, Scripts / JavaScript / May 2005



Tip: Looking for answers? Try searching our database.

Multiple arguments to a function??

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
JS - 31 May 2005 16:13 GMT
I have this form in test.jsp, that consists of 3 drop/down menus (sel1, sel2
and sel3):

<body onload="createFirstMenu('sel1');">
<form name="sels" method="post" action="">

<select name="sel1" id="sel1" onchange="createSecondMenu('sel1','sel2',
'sel3');">
</select>

<select name="sel2" id="sel2" onchange="createThirdMenu('sel1','sel2',
'sel3');">
 <option value="0">-- V&aelig;lg --</option>
</select>

<select name="sel3" id="sel3" onchange="update('sel1', 'sel2', 'sel3');">
 <option value="0">--V&aelig;lg--</option>
</select>

</form>

In a javaScript I have the functions: createFirstMenu, createSecondMenu,
createThirdMenu and update.

If I choose something from sel1 "createSecondMenu" gets called with 3
arguments:

function createSecondMenu(sel){
var s = new Array(); // s holds the menus.
//s[0] = document.getElementById(arguments[0]); // s[0] contains the first
menu.
//s[1] = document.getElementById(arguments[1]); // s[1] contains the second
menu.
//s[2] = document.getElementById(arguments[2]); // s[2] contains the third
menu.
sel = s[1]; // sel now contains the second menu.

var choice1 = s[0].selectedIndex; // The index in the first menu.
var choice2 = s[1].selectedIndex; // The index in the second menu.
var choice3 = s[2].selectedIndex; // The index in the third menu.
resetMenu(sel);
}

But I just realized that choice1-3 contains the selected index from the 3
menus even when out comment the lines where I grap the arguments.

How can s[0], s[1] and s[2] contain the selected index from the right
drop/down menus when they don't contain a SELECT object???
Michael Winter - 31 May 2005 18:02 GMT
> I have this form in test.jsp [...]

Instead of constantly posting untestable fragments of code, post a URL
to a (semi-)workable page that can be examined properly.

> <body onload="createFirstMenu('sel1');">

If this is for the Web, you should probably give this endeavor up:
constructing forms in this way is not a good way to author for a public
audience.

Richard Cornford has a method for producing dependent SELECT elements
without server-side support.

<URL:http://www.litotes.demon.co.uk/example_scripts/dependent_select.html>

Of course, if you have server-side support (and you do), then you should
just use that instead. Granted, it requires round trips to the server,
but at least it's reliable and doesn't force the user to download
options they may never need to select.

[Musing]
It would be nice if OPTGROUP elements could be nested. That would
produce a much nicer scriptable structure, and possibly help with
usability, too.
[/Musing]

> <select [...] onchange="createSecondMenu('sel1','sel2', 'sel3');">
> </select>

SELECT elements are required to have at least one OPTION element.

[snip]

> //s[0] = document.getElementById(arguments[0]); // s[0] contains the
> first

Stop using the getElementById method to access form controls. Use the
forms and elements collections instead.

[snip]

> How can s[0], s[1] and s[2] contain the selected index from the right
> drop/down menus when they don't contain a SELECT object???

They don't. Common sense should tell you that. The script will (and
does) error out.

Mike

Signature

Michael Winter
Replace ".invalid" with ".uk" to reply by e-mail.

 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.