|
-
Aug 17th, 2004, 03:19 AM
#1
Thread Starter
Lively Member
Javascript: Select Options [Resolved]
Hi,
I've 2 select boxes. When the user changes the option in the first select box, the options in the second select box will change/populated.
I used the onchange event on the first select box, but the options in the second select box is not populated.
My codes:
Code:
<html>
<head>
<script language="Javascript">
var NW = new Array("Network/User Admin", "Hardware", "Software");
var BA = new Array("Email", "Intranet");
function main_change(mymain) {
var _main = mymain.value;
if (_main == "NW") {
for (var k=0; k< NW.length; k++) {
OPT = new Option;
OPT.Text= NW[k];
OPT.Value= NW[k];
document.forms['issue']['subCat'].options[k] = OPT;
}
}
else if (_main == "BA") {
for (var k=0; k< BA.length; k++) {
OPT = new Option;
OPT.Text= NW[k];
OPT.Value= NW[k];
document.forms['issue']['subCat'].options[k] = OPT;
}
}
}
</script>
</head>
<body>
<form name="issue">
<table>
<tr>
<td>Main Category:</td>
<td width=10> <select name="main" onchange="main_change(this);">
<option>Please Choose One...</option>
<option value="NW">Network</option>
<option value="BA">Business App</option>
</select>
</td>
<td>Sub Category:</td>
<td> <select name="subCat">
<option>Please Choose One...</option>
</select>
</td>
</tr>
</table>
</form>
</body>
</html>
Last edited by velvetskies; Aug 17th, 2004 at 07:21 PM.
-
Aug 17th, 2004, 08:08 AM
#2
its the length part not returning the number of array sections.
I'm looking into it a little more.
Vince
Feeling like a fly on the inside of a closed window (Thunk!)
If I post a lot, it is because I am bored at work! ;D Or stuck...
* Anything I post can be only my opinion. Advice etc is up to you to persue...
-
Aug 17th, 2004, 08:29 AM
#3
Info on array
Ok, looking here it appears to be a problem setting the array.
I've changed the code a little to assign values to the array, but for some reason it isn't setting them in the loop, almost as though its not seeing the variables...
Vince
Code:
<html>
<head>
<script language="Javascript">
var NW = new Array(3);
NW[0]="Network/User Admin"
NW[1]="Hardware"
NW[2]="Software"
var BA = new Array(2);
BA[0]="Email"
BA[1]="Intranet"
alert(BA.length);
function main_change(mymain) {
var _main = mymain.value;
if (_main == "NW") {
for (var k=0; k< NW.length; k++) {
OPT = new Option;
OPT.Text= NW[k];
OPT.Value= NW[k];
document.forms['issue']['subCat'].options[k] = OPT;
}
}
else if (_main == "BA") {
for (var k=0; k< BA.length; k++) {
OPT = new Option;
OPT.Text= NW[k];
OPT.Value= NW[k];
document.forms['issue']['subCat'].options[k] = OPT;
}
}else{
alert("None");
}
}
</script>
</head>
<body>
<form name="issue">
<table>
<tr>
<td>Main Category:</td>
<td width=10> <select name="main" onchange="main_change(this);">
<option>Please Choose One...</option>
<option value="NW">Network</option>
<option value="BA">Business App</option>
</select>
</td>
<td>Sub Category:</td>
<td> <select name="subCat">
<option>Please Choose One...</option>
</select>
</td>
</tr>
</table>
</form>
</body>
</html>
Feeling like a fly on the inside of a closed window (Thunk!)
If I post a lot, it is because I am bored at work! ;D Or stuck...
* Anything I post can be only my opinion. Advice etc is up to you to persue...
-
Aug 17th, 2004, 08:37 AM
#4
Hmm - seems to be how you are resetting the combo list now... not working.
Good luck in finding the result

Vince
Feeling like a fly on the inside of a closed window (Thunk!)
If I post a lot, it is because I am bored at work! ;D Or stuck...
* Anything I post can be only my opinion. Advice etc is up to you to persue...
-
Aug 17th, 2004, 07:01 PM
#5
Thread Starter
Lively Member
Hi Ecniv,
Thanks for the reply!
Changing the way of assigning values to the array doesnt seem to have a difference between the outputs of my codes and yours.
i've checked out the options' values by..
alert(document.forms['issue']['subCat'].options[a].Value);
and they're populated with the array values (both ways of assigning array values)
I'll contd to find the way out..
But anyway, appreciate it. thanks again
-
Aug 17th, 2004, 07:20 PM
#6
Thread Starter
Lively Member
Haha.. it should be
OPT = new Option(NW[k], NW[k]);
Yay!
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|