By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,688 Members | 1,900 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,688 IT Pros & Developers. It's quick & easy.

onChange problem with two dropdowns and one form

P: n/a
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
Jul 20 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
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>

Jul 20 '05 #2

P: n/a
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" <RE**************@cox.net> wrote in message
news:bk********@drn.newsguy.com...
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.parentcauses 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>

Jul 20 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.