Reply
Dropdown onclick
Old 07-21-2005, 10:26 AM Dropdown onclick
Jdawg's Avatar
Experienced Talker

Posts: 38
Location: NB, Canada
Hello, Javascript is not my cup of tea but I'm faced with a client that wants it a certain way.

I need to hide/display a DIV when you click on a form dropdown. Here's the not functioning code.

Code:
<style type="text/css">
#one,#two,#three{visibility:hidden;position:absolute;height:200px;width:300px;}
</style>

<script type="text/javascript">
function radFlip(){
var l=document.firstForm.dropdown.radOne.length;
for(var i=0;i<l;i++){
var to_see=document.firstForm.dropdown.radOne[i].value;
if(document.firstForm.dropdown.radOne[i].selected){
document.getElementById(to_see).style.visibility="visible";
}else{
document.getElementById(to_see).style.visibility="hidden";
}
}
}
</script>

Code:
<form action="" name="firstForm" onclick="radFlip();"> 
<select name="dropdown">
	<option name="radOne" value="one" selected>One</option>
	<option name="radOne" value="two">Two</option>
	<option name="radOne" value="three">Three</option>
</select>
</form> 

<div id="one">test 1</div>
<div id="two">test 2</div>
<div id="three">test 3</div>
I think the first problem is the script is not recognizing the form, and the second is I don't know if the .selected will actually work.

If anyone could shed some light. THANKS!!!
__________________
Jdawg
Sirius Solutions

"I know because I must know, it is my purpose" - keymaker
Jdawg is offline
Reply With Quote
View Public Profile
 
When You Register, These Ads Go Away!
Old 07-21-2005, 12:07 PM
WebcyteDesign's Avatar
Extreme Talker

Posts: 159
Location: Hamilton
http://aspnet.4guysfromrolla.com/articles/091504-1.aspx

That article should help you out. It did for me.
WebcyteDesign is offline
Reply With Quote
View Public Profile Visit WebcyteDesign's homepage!
 
Old 07-21-2005, 12:53 PM
Jdawg's Avatar
Experienced Talker

Posts: 38
Location: NB, Canada
Thx for the link. Although this method won't help me since it uses a button to make the action instead of clicking on a drop down option. From the looks of it, the method of which the action is taking place (i.e. radio button, input button) makes a significan difference in the code.

Unfortunatly, I need it specifically for a drop down.
__________________
Jdawg
Sirius Solutions

"I know because I must know, it is my purpose" - keymaker
Jdawg is offline
Reply With Quote
View Public Profile
 
Old 07-21-2005, 05:41 PM
chrishirst's Avatar
Super Moderator

Posts: 13,511
Location: Blackpool. UK
use the onSelect event in place of the onClick event.
__________________
Chris. ->> Links are advertising NOT optimising!! <<-
Indifference will be the downfall of mankind, but who cares?
Code Samples | People Counting System
chrishirst is offline
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Reply     « Reply to Dropdown onclick
 

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off




   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML

 


Page generated in 0.12321 seconds with 12 queries