954,604 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

if with radio button or dropdown..

I need to make a form with a few options could be radio or drop down, ex a, b, and c..
and when one is selected I would have a if command that would give you another set of options like if option "a" is selected then in the same page would come up another set of options like a1, a2, a3.. or if "b" is selected then options b1, b2, b3 and so on..

thanks for the help..

davidrooker
Newbie Poster
4 posts since Jul 2010
Reputation Points: 10
Solved Threads: 0
 

HTML

<select name="select1" id="select1" onChange="return changeForm();">
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
</select>
<select name="select2" id="select2">
</select>


JavaScript

function changeForm(){
var a = document.getElementById("select1");
var b = document.getElementById("select2");
var c = a.options[a.selectedIndex].value;
if(c == 1){
b.innerHTML = '<option value="1.1">1</option><option value="1.2">2</option>';
}
if(c == 2){
b.innerHTML = '<option value="2.1">1</option><option value="2.2">2</option>';
}
if(c == 3){
b.innerHTML = '<option value="3.1">1</option><option value="3.2">2</option>';
}
}
phpl0v3r
Newbie Poster
10 posts since Jul 2010
Reputation Points: 9
Solved Threads: 1
 

so all I have to do is put the form values i want for the 2nd set of options in the b.innerHTML field?

davidrooker
Newbie Poster
4 posts since Jul 2010
Reputation Points: 10
Solved Threads: 0
 

exactly.

phpl0v3r
Newbie Poster
10 posts since Jul 2010
Reputation Points: 9
Solved Threads: 1
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: