onChange problem with two dropdowns and one form

P

Phil Powell

I have a form with two single-choice dropdowns. Upon doing an onChange
event on either one of them, I want to check to see if the other dropdown
has also been selected. How would I do that, considering that this.parent
causes an error "null or not an object"?

Thanx
Phil
 
L

Lee

Phil Powell said:
I have a form with two single-choice dropdowns. Upon doing an onChange
event on either one of them, I want to check to see if the other dropdown
has also been selected. How would I do that, considering that this.parent
causes an error "null or not an object"?

The "parent" attribute is an attribute of windows.
Form elements have an attribute named "form", which is a reference
to the containing form.

<html>
<head>
<script type="text/javascript">
function seeIfBothChosen(f){
if(f.select1.selectedIndex && f.select2.selectedIndex){
alert(f.select1.options[f.select1.selectedIndex].text + " / " +
f.select2.options[f.select2.selectedIndex].text);
}
}
</script>
</head>
<body>
<form>
<select name="select1" onchange="seeIfBothChosen(this.form)">
<option>--Choose--</option>
<option>alpha</option>
<option>beta</option>
</select>
<select name="select2" onchange="seeIfBothChosen(this.form)">
<option>--Choose--</option>
<option>gamma</option>
<option>delta</option>
</select>
</form>
</body>
</html>
 
P

Phil Powell

Ok cool, is there then an easier way to check then that if one dropdown has
been selected that so has the other within the same form?

Thanx
Phil

Lee said:
Phil Powell said:
I have a form with two single-choice dropdowns. Upon doing an onChange
event on either one of them, I want to check to see if the other dropdown
has also been selected. How would I do that, considering that this.parent
causes an error "null or not an object"?

The "parent" attribute is an attribute of windows.
Form elements have an attribute named "form", which is a reference
to the containing form.

<html>
<head>
<script type="text/javascript">
function seeIfBothChosen(f){
if(f.select1.selectedIndex && f.select2.selectedIndex){
alert(f.select1.options[f.select1.selectedIndex].text + " / " +
f.select2.options[f.select2.selectedIndex].text);
}
}
</script>
</head>
<body>
<form>
<select name="select1" onchange="seeIfBothChosen(this.form)">
<option>--Choose--</option>
<option>alpha</option>
<option>beta</option>
</select>
<select name="select2" onchange="seeIfBothChosen(this.form)">
<option>--Choose--</option>
<option>gamma</option>
<option>delta</option>
</select>
</form>
</body>
</html>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,764
Messages
2,569,564
Members
45,039
Latest member
CasimiraVa

Latest Threads

Top