maztt
maztt

Reputation: 12294

jquery radiobutton select value

  <input type="radio" name="regenerate" value="1" id="cus" />
         <input type="radio" name="regenerate" value="2" id="gen" />
         <input type="checkbox" name="renerateEmail" id="renerateEmail" />
     <div id="txt" style="display:none"><input type="password" name="pass" id="pass" /><br />
     <input type="password" name="repass" id="repass" /></div>

i want to hide and show the div "txt" when radio button has the value 1 , how can i do that.

Upvotes: 0

Views: 1911

Answers (3)

rob waminal
rob waminal

Reputation: 18429

maybe this

$("input[name=regenerate]").click(function(){
    if($(this).val() == 1) {
        $("#txt").show();
    } else {
        $("#txt").hide();
    }
});

Upvotes: 1

Scott Evernden
Scott Evernden

Reputation: 39986

"hide and show".. "has the value 1" - ?not precisely clear what you want but .. here's one way

$(':radio[name=regenerate]').click(function() {
  if ($(':radio[name=regenerate]:checked').val() == 1)
    $('#txt').show()
  else
    $('#txt').hide();
})

Upvotes: 0

Paul Schreiber
Paul Schreiber

Reputation: 12599

You request isn't clear. Do you want to hide the div when the radio button is 1 and show it when it's 2? Or what?

You want something like:

if ($("#cus:checked").length == 1) {
  $("#txt").show();
}

Upvotes: 0

Related Questions