javascript - group radio buttons and toggle input controls using jQuery -


i want show textboxes of selected radiobutton only. works such. problem when click on textbox type anything, toggle. , radio button selection doesn;t change current selection. please find detailed code below

<html> <head> <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.5/jquery.min.js"> </script> <script>  $(document).ready(function()  {    $(".userid_textbox").hide();    $(".userid").click(function()    {      var kid=$(this).children(".userid_textbox");      var dad=$(this).parent();      var toggledkid = $(dad).find('.toggle');      $(kid).addclass("toggle").show('slow');      $(toggledkid).hide('slow').removeclass('toggle');    }); }); </script> </head> <body> <div class="contentbox tp">  <h1 class="heading">sites list</h1>    <div style="float:left;margin-right:185px;" class="userid">    <input type="radio" id="" value="search userid" checked/>search userid   <div class="userid_textbox">    <input id="username" maxlength="50" name="username" style="width: 50%;      font-size: 25px;" tabindex="1" type="text" value="" />    </div>   </div>    <div style="float:left;margin-right:100px;display:inline;" class="userid">    <input type="radio" id="" value="search sitename"/>search sitename   <div class="userid_textbox">    <input id="username2" maxlength="50" name="username1" style="width: 50%;      font-size: 25px;" tabindex="1" type="text" value="" />    </div>   </div>    <div style="float:left;margin-right:50px;display:inline;" class="userid">    <input type="radio" id="" value="search expiry date"/>search      expiry date   <div class="userid_textbox">    <input id="username3" maxlength="50" name="username2" style="width: 50%;      font-size: 25px;" tabindex="1" type="text" value="" />    </div>   </div>   </div>  </body> </html> 

there go: http://jsfiddle.net/s7cby/

you need add same name attribute radio buttons group them, i.e.:

<input type="radio" name="searchby" id="" value="search userid" checked/>      search userid <input type="radio" name="searchby" id="" value="search sitename"/>     search sitename <input type="radio" name="searchby" id="" value="search expiry date"/>     search expiry date 

and clean-up jquery so:

$(document).ready(function() {   $(".userid_textbox").hide();   $('[name="searchby"]').click(function()   {     $(".userid_textbox").hide();     $(this).next(".userid_textbox").show();   }); }); 

Comments

Popular posts from this blog

c# - SharpSVN - How to get the previous revision? -

c++ - Is it possible to compile a VST on linux? -

url - Querystring manipulation of email Address in PHP -