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

Popular posts from this blog

node.js - Mongoose: Cast to ObjectId failed for value on newly created object after setting the value -

[C++][SFML 2.2] Strange Performance Issues - Moving Mouse Lowers CPU Usage -

ios - Possible to get UIButton sizeThatFits to work? -