473,569 Members | 2,598 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 4122
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.se lectedIndex && f.select2.selec tedIndex){
alert(f.select1 .options[f.select1.selec tedIndex].text + " / " +
f.select2.optio ns[f.select2.selec tedIndex].text);
}
}
</script>
</head>
<body>
<form>
<select name="select1" onchange="seeIf BothChosen(this .form)">
<option>--Choose--</option>
<option>alpha </option>
<option>beta</option>
</select>
<select name="select2" onchange="seeIf BothChosen(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.co m...
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.se lectedIndex && f.select2.selec tedIndex){
alert(f.select1 .options[f.select1.selec tedIndex].text + " / " +
f.select2.optio ns[f.select2.selec tedIndex].text);
}
}
</script>
</head>
<body>
<form>
<select name="select1" onchange="seeIf BothChosen(this .form)">
<option>--Choose--</option>
<option>alpha </option>
<option>beta</option>
</select>
<select name="select2" onchange="seeIf BothChosen(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
20685
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 init() {
1
2584
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 print to the browser which includes some data displayed and edittable in <FORM> elements. There are a couple areas where I display a message or a...
13
31254
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 supposed to check all the checkboxes, which it does (that's not rocket science ;), but the 'onchange' event does not get triggered.
4
4076
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 dependant on data collected in the code behind on the server. I have set AutoPostback to false for the controls and added lines such as...
1
3752
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 to reload when county changes. I remember doing this before in classic ASP with javascript, can I do this with a dropdownlist in ASP.NET or should...
3
3968
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 a couple of problems, which I'll try to describe. But this e-mail will only reproduce one of them, in a "short" example. What I'm generally doing...
4
47963
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 onChange embedded in the "password" field. This is normal HTML and it works fine. <HTML> <HEAD><TITLE> Example of onChange Event Handler </TITLE> ...
6
2155
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. options.value } //-->
0
7614
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
8125
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
0
6284
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5513
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5219
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3653
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3642
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2114
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
0
938
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.