...

View Full Version : how do i only show a input text box if select option is present



devinmaking
12-16-2011, 04:10 PM
Hi Guys i am a complete novice at ajax or javascript.

I have been studying php for a while now and i know that, i am now starting php oop and that going well but i have never done anything like this.

Anway i am creating a booking system which at the end of the process asks who supplied your voucher which they then select a supplier.

The issue i have is my client wants it so if groupon is selected then an input text box should appear so that the user can input a security code from groupon.

So basically it is


<select name="supplier" id="supplier">
<option value="">please select supplier</option>
<option value="Groupon">Groupon</option>
<option value="KGB Deals">KGB Deals</option>
<option value="Other">Other</option>
</select>

So if value="Groupon" then
<input type="text" name="security" id="security" /> should appear next to it.

Could someone please help me as the page cant refresh as it will lose its data which would have taken the user about 10 minutes to fill out :(

Thanks in advance :)

Rowsdower!
12-16-2011, 04:33 PM
Start off with display:none; style on "security."

Then you need an onchange event handler for "supplier" to check the new value given in that dropdown. If the value is "Groupon" then give "security" block display style.

Very roughly like this:
<select name="supplier" id="supplier" onchange="if(this.value=='Groupon'){document.getElementById('security').style.display='block';}else{document.g etElementById('security').style.display='none';}">
<option value="">please select supplier</option>
<option value="Groupon">Groupon</option>
<option value="KGB Deals">KGB Deals</option>
<option value="Other">Other</option>
</select>

<input type="text" name="security" id="security" style="display:none;" />

You should get the inline stuff pulled out into external commands and styles of course, but this illustrates the most basic approach to this behavior.

devinmaking
12-16-2011, 05:34 PM
Start off with display:none; style on "security."

Then you need an onchange event handler for "supplier" to check the new value given in that dropdown. If the value is "Groupon" then give "security" block display style.

Very roughly like this:
<select name="supplier" id="supplier" onchange="if(this.value=='Groupon'){document.getElementById('security').style.display='block';}else{document.g etElementById('security').style.display='none';}">
<option value="">please select supplier</option>
<option value="Groupon">Groupon</option>
<option value="KGB Deals">KGB Deals</option>
<option value="Other">Other</option>
</select>

<input type="text" name="security" id="security" style="display:none;" />

You should get the inline stuff pulled out into external commands and styles of course, but this illustrates the most basic approach to this behavior.

Thank you for the help, worked a treat :)



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum