Click to See Complete Forum and Search --> : Changing fields on select?


kaos057
07-18-2003, 02:46 PM
Ok, I am making a site which has an account creation type thing.

What I need to do, is have a drop down menu that has the options 'Business' and 'Residential'. When one of those are selected the next input field changes to suit it.

Say business is selected, the next line would be a text input for the business name. If residential was selected, the next line would be an input for first name, then an input for last name.

How would I go about doing this? Thanks in advance.

pyro
07-18-2003, 03:00 PM
You could try something like this:

<script type="text/javascript">
function showFields(sel) {
val = sel.options[sel.selectedIndex].value;
if (val == "business") {
document.getElementById("business").style.display = "block";
document.getElementById("residential").style.display = "none";
}
if (val == "residential") {
document.getElementById("business").style.display = "none";
document.getElementById("residential").style.display = "block";
}

}
</script>

</head>

<body>

<form>

<select name="myselect" onclick="showFields(this);">
<option value="Choose">Please Choose</option>
<option value="business">Business</option>
<option value="residential">Residental</option>
</select>

<div id="business" style="display:none;">
Business Name: <input type="text">
</div>

<div id="residential" style="display:none;">
First: <input type="text"><br>
Last: <input type="text">
</div>
</form>