473,406 Members | 2,954 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

Multiple arguments to a function??

JS
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???

Jul 23 '05 #1
1 1885
On 31/05/2005 16:13, JS wrote:
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

--
Michael Winter
Replace ".invalid" with ".uk" to reply by e-mail.
Jul 23 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

66
by: Darren Dale | last post by:
Hello, def test(data): i = ? This is the line I have trouble with if i==1: return data else: return data a,b,c,d = test()
17
by: Roland Hall | last post by:
Is there a way to return multiple values from a function without using an array? Would a dictionary object work better? -- Roland Hall /* This information is distributed in the hope that it...
1
by: grandeandy | last post by:
question: in the code below, and in general, how would I input multiple functions into the code, and get multiple outputs? basically, I want to be able to add say 2 or 3 of the div's to the link so...
20
by: km | last post by:
Hi all, In the following code why am i not able to access class A's object attribute - 'a' ? I wishto extent class D with all the attributes of its base classes. how do i do that ? thanks in...
5
by: deko | last post by:
I'd like to use a bit of code in the OnOpen event of a report: =rptOpen(Me.ReportName), (Me.Tag) --this doesn't work This does work: Private Sub Report_Open(Cancel As Integer)...
1
by: glennpierce | last post by:
Hi I was wondering if anyone knows of a method to achieve the creation of events in c. currently I use a function pointer to call one callback. However, I really need to map the function pointer or...
47
by: Mark | last post by:
why doesn't .NET support multiple inheritance? I think it's so silly! Cheers, Mark
8
by: aleksandar.ristovski | last post by:
Hello all, I have been thinking about a possible extension to C/C++ syntax. The current syntax allows declaring a function that returns a value: int foo(); however, if I were to return...
7
by: andrewfsears | last post by:
I have a question: I was wondering if it is possible to simulate the multiple constructors, like in Java (yes, I know that the languages are completely different)? Let's say that I have a class...
1
by: ashokbio | last post by:
How to return multiple values by passing multiple arguments in function or subroutine using VB6? T. Ashok Kumar
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.