javascript - How to Hide/Show 'div' using jQuery? -
how can show text box depending on user's selection in dropdown box?
<select name="sites" id="select5" required="yes"> <?php for($i=0;$i<=128;$i++){ echo "<option>".$i."</option>"; } ?> </select> <div id="yes"> other: <input class="input-text" type="text" name="name"/> </div>
if user selects 1 - text box not show. if user selects more 2 -> <div id="yes">
show.
here's jquery:
<script type="text/javascript"> $(document).ready(function(){ $('#yes').hide(); $("#select5").change(function(){ $('#yes').hide('slow'); $("#" + this.value).show('slow'); }); }); </script>
any suggestions?
you can call hide/show based on value of select like
$(document).ready(function () { $('#yes').hide(); $("#select5").change(function () { $('#yes')[this.value > 1 ? 'show' : 'hide']('slow'); }); });
demo: fiddle
Comments
Post a Comment