Flash Games
 FAQ   Search   Memberlist   Usergroups   Register  Profile   Log in to check your private messages   Log in 


Using onChange with a Select statement



 

Post new topic   Reply to topic  
   DEVPPL Forum Index -> JavaScript Forum
View previous topic :: View next topic  
Author Message
webphotogeek



Joined: 27 Feb 2008
Posts: 7

PostPosted: Thu Jun 05, 2008 7:59 pm    Post subject: Using onChange with a Select statement Reply with quote

Can someone tell me the correct syntax for the Select statement that uses the onChange event? Here's what I have, which is obvioulsy not working:

<script type="text/javascript">
function mainOptions(optionsVar) {
if (OptionsVar == 'Medical') {
document.getElementById('medical').style.display="";
}
}
</script>

<form name="expenses">
<p><select id="selOptions" onChange="mainOptions(this);"></p>
<option>Please Select</option>></p>
<p><option>Photography</option> </p>
<p><option>Computers</option></p>
<p><option>Medical</option></p>
<p><option>Other</option></p>
</select>
</form>
Back to top
View user's profile Send private message
rangana
500+ Club


Joined: 27 Feb 2008
Posts: 560
Location: Cebu City Philippines

PostPosted: Fri Jun 06, 2008 12:45 am    Post subject: Re: Using onChange with a Select statement Reply with quote

First, it's erroneous since you don't have an element having the id of medical yet. Or you just missed showing it to us.

JS is case-sensitive. Capitalization matters.

Here are the changes, highlighted are added:

<script type="text/javascript">
function mainOptions(optionsVar) {
if (optionsVar.value == 'Medical') {
document.getElementById('medical').style.display="";
}
}
</script>

See if it helps.
Back to top
View user's profile Send private message Yahoo Messenger
webphotogeek



Joined: 27 Feb 2008
Posts: 7

PostPosted: Fri Jun 06, 2008 5:22 pm    Post subject: Re: Using onChange with a Select statement Reply with quote

Thanks and I did leave out the id part:

<div id="medical">
Enter Medical Option:&nbsp;
<p><select name="medical_options"></p>
<p><option>co-pays</option> </p>
<p><option>Perscriptions</option></p>
<p><option>Travel</option></p>
<p><option>Other</option></p>
</select>
</div>


and the 'O' was a typo, but I did correct it and added '.value', but I am still getting no value. I tested it with alert(optionsVar.value).

Am I using 'this' properly in mainOptions(this)? Or am I supposed to use something like this - onChange="mainOptions(document.expenses.selOptions.options[document.expenses.selOptions.selectedIndex].value);"

Thanks for you help. I am confused, but once I get passed this part, I should understand it better.

- Steve
Back to top
View user's profile Send private message
rangana
500+ Club


Joined: 27 Feb 2008
Posts: 560
Location: Cebu City Philippines

PostPosted: Sat Jun 07, 2008 3:35 am    Post subject: Re: Using onChange with a Select statement Reply with quote

The way you position your divs is erroneous!.

Have it outside your combobox.
Back to top
View user's profile Send private message Yahoo Messenger
Display posts from previous:   
Post new topic   Reply to topic    DEVPPL Forum Index -> JavaScript Forum All times are GMT + 1 Hour
Page 1 of 1

 
 
Welcome to DEVPPL.com
You are not logged in, which means that you can't post in the forums.
Click here to Register

If you are a current member here on DEVPPL, please login below:

User: Pass:
Log me on automatically each visit:

 


Powered by phpBB © 2001, 2005 phpBB Group - Modified by DEVPPL

Flash Games - Sitemap