473,385 Members | 1,588 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,385 software developers and data experts.

onChange problem with two dropdowns and one form

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
2 4097
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Covad | last post by:
Hi all, For some reason my change() function is only called when the page loads. I'd much rather it gets called when the select changes. Here's the code: window.onload = init; function...
1
by: dan baker | last post by:
I am pretty much a newbie with javascript, and would like to get a little clarification on what I can do with an onChange javascript event handler. I have a dynamic page I build with perl and...
13
by: aundro | last post by:
Hello, I've been looking on the web for a solution to this problem: I create a set of checkboxes, and 2 buttons: - one is labeled "All" - the other is labeled "None" Clicking "All" is...
4
by: Zeebra3 | last post by:
Here goes: I have a web form with several asp:dropdownlists, with which, when selection is changed I want to fire an event defined in some clientside js. The content of the clientside code is...
1
by: Stimp | last post by:
I have 2 dropdowns, county and district. When the county changes, I want the district dropdown to automatically update with a list of districts in that county, but I don't want the page to have...
3
by: jab3 | last post by:
Hello. I"m new to this group, and to JavaScript in general, so please forgive me if I breach local etiquette. I'm trying to implement some client-side 'dynamic' validation on a form. I'm having...
4
by: auslandt | last post by:
I have an HTML file that includes a JavaScript. I would like this JavaScript to be able to create an "onChange=<function>" attribute against the password element. Here is an example page of the...
6
by: idj | last post by:
Hi, I'm using the following code to redirect to a new page with a select dropdown, which works fine: <script type="text/javascript"> <!-- function go(){ location= document.FRM_NAME.VALUE_NAME....
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

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.