...

View Full Version : How to change a form based on select option?



CrackTheAir
05-25-2009, 06:18 PM
Hi, I don't know if this is something you could do without JavaScript, but anyways...
I want to make a drop down menu that changes a form based on the option, like if I chose Option1, it would show Form1 and so on.

And also, if anyone knows how to list items in a div, that would be helpful too.

Thanks.

Philip M
05-25-2009, 06:46 PM
Try this:-


<select id = "opts" onchange = "showForm()">
<option value = "0">Select Option</option>
<option value = "1">Option 1</option>
<option value = "2">Option 2</option>
</select>

<div id = "f1" style="display:none">
<form name= "form1">
Content of Form 1
</form>
</div>

<div id = "f2" style="display:none">
<form name= "form2">
Content of Form 2
</form>
</div>

<script type = "text/javascript">
function showForm(){
var selopt = document.getElementById("opts").value;
if (selopt == 1) {
document.getElementById("f1").style.display="block";
document.getElementById("f2").style.display="none";
}
if (selopt == 2) {
document.getElementById("f2").style.display="block";
document.getElementById("f1").style.display="none";
}
}

</script>

"The reward for conformity was that everyone liked you except yourself". - Rita Mae Brown.

CrackTheAir
05-25-2009, 06:55 PM
Thanks, that's just what I needed :)



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum