Go Back   CodingForums.com > :: Client side development > JavaScript programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 03-23-2005, 01:50 PM   PM User | #1
reasr
New Coder

 
Join Date: Mar 2005
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts
reasr is an unknown quantity at this point
hide some options of dropdown menu

Hi,

i have a form with some checkbox and dropdown list

if T-shirt option is checked i want to hide the ball options from the dropdown list, and if Ball option is checked i want to hide the T-shirt options

how to do that

Regards,

<html>

<head>

<title>test</title>
</head>

<body>

<form name=calc >
<input type="checkbox" name="tshirt" value="ON">T-shirt
<select size="1" name="description">
<option>Nike</option>
<option>Addidas</option>
<option>Fila</option>
<option>Basket Ball</option>
<option>Football</option>
<option>Tennis Ball</option>
</select></p>
<input type="checkbox" name="ball" value="ON">Ball
</form>

</body>

</html>
reasr is offline   Reply With Quote
Old 03-23-2005, 03:49 PM   PM User | #2
eric6930
New to the CF scene

 
Join Date: Mar 2005
Location: Toronto
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
eric6930 is an unknown quantity at this point
You need to populate the select box dynamically using pre-built arrays. For example,
var aBalls = new Array ("Basket Ball", "Football", "Tennis Ball");
var aTshirts = new Array ("Nike", "Addidas", "Fila");

Initially, you populate your select box with one set of values only.

Then, attach a function on the onClick event to the check-boxes. For example,

function hide(){
if(document.calc.tshirt.checked){
for(var i=0; i<aTshirts.length;i++){
document.calc.description.options[i]=new Option (aTshirts[i]);
}
}
if(document.calc.ball.checked){
for(var i=0; i<aBalls.length;i++){
document.calc.description.options[i]=new Option (aBalls[i]);
}
}

}

You are probably better off using radio buttons instead of check-boxes.

Hope this helps.
__________________
JavaScript tips and scripts
eric6930 is offline   Reply With Quote
Old 03-30-2005, 01:32 PM   PM User | #3
reasr
New Coder

 
Join Date: Mar 2005
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts
reasr is an unknown quantity at this point
how about if i want to put values to the dropdown list items???


Regards,


reasr
reasr is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

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

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 02:59 AM.


Advertisement
Log in to turn off these ads.