Click to See Complete Forum and Search --> : drop down sets input field? how do I do it?


etard
09-24-2003, 03:01 PM
I have a form on site that asks if you want to be contacted via phone. You can select 'Yes" or 'No' via a drop down. The field after the drop down is an input field that asks for the phone number if you answered 'Yes" to the above question. Well, I think it would be better that if you answered "Yes" to the drop down question that the phone number input filed either (1) becomes active and you can type in it OR (2) has a text message show up in it that says "be sure to provide your phone number". If "No" is selected, you cannot enter or use the phone number filed would be optional. Point is, I am looking for a way to prompt people to enter the number in the filed if they answer "Yes" and I think a drop down that sets an input field would be a neat solution.

pyro
09-24-2003, 03:21 PM
Try something like this:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>Example</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<script type="text/javascript">
function setField(frm) {
if (frm.yesno.options[frm.yesno.selectedIndex].value == "yes") {
frm.phonenum.value = "Please input your phone number";
}
else {
frm.phonenum.value = "You my optionally enter your phone number";
}
}
</script>
</head>
<body>
<form name="myform" action="">
<p><select name="yesno" onchange="setField(this.form);">
<option value="">Please Choose</option>
<option value="yes">Yes</option>
<option value="no">No</option>
</select>
<input type="text" name="phonenum"></p>
</form>
</body>
</html>

etard
09-24-2003, 07:51 PM
peeeeeerfect. exactly what I wanted. I added an onFocus element to the phone field to clear it when the cursor is put into so they can add their phone number and BAM- works perfect. Thanks!

pyro
09-24-2003, 09:12 PM
You're welcome... :)