Deaf World - Self Improvement Articles Directory - Find jobs - free machines directory - Find jobs

PDA

View Full Version : On selection do something


PHPGator
Oct 4th 2007, 8:18 am
Hello,

I am pretty bad at javascript. Essentially I have a form with a pulldown menu. In the pulldown menu there is a "Other" option. WHat I want to happen when the user selects "other" is for another field to appear next to it and allow them to type in something.

Can someone show me an example? I couldn't find one online but I know it is possible. :)

Synchronium
Oct 4th 2007, 9:45 am
onchange="if( this.value = 'other' ) { do_shit(); }"

joesgraphics
Oct 4th 2007, 10:13 am
How is the text box going to be displayed is it just hidden or would you like it to be created in js.

PHPGator
Oct 4th 2007, 10:17 am
I was using just standard HTML to create the form.

<select name="color">
<option value="Other">Other</option>
</select>

That is how I currently have it setup (minus some css stuff).

I Just want a <input type="text" name="other"> to appear if Other is selected in the pull down menu.

joesgraphics
Oct 4th 2007, 10:50 am
I was using just standard HTML to create the form.

<select name="color">
<option value="Other">Other</option>
</select>

That is how I currently have it setup (minus some css stuff).

I Just want a <input type="text" name="other"> to appear if Other is selected in the pull down menu.

Ill pm you.

james_r
Oct 5th 2007, 7:17 pm
<script>
function ShowHideTextBox() {
if (document.getElementByName("color").value == "Other")
{
document.getElementById("textboxDiv").style.display = "block";
}
else
{
document.getElementById("textboxDiv").style.display = "none";
}
}
</script>


<select name="color" onclick="ShowHideTextBox()">
<option value="Other">Other</option>
</select>

<div style="display:none;" id="textboxDiv">
<input name="this_is_the_text_box" />
</div>