0

jQuery

$(document).ready(function(){
  $("#cityshow").click(function(){
    $("#citybox").toggle();
  });

    $('#citybox input[type=radio]').click(function(){
        var buttonValue = $(this).val();
        $("#citybox").toggle();
        $('#cityshow').html(buttonValue);
    });
});

HTML

<form action="search.php" name="search" method="get" id="search">
       <input type="hidden" value="" id="cityshow">
        <div id="cityshow" class="citybox">Sikar</div>
       <div id="citybox" class="citycollection">
       <div style="height:0px; border-bottom:1px solid #333; width:62.5%; margin:0px; float:right   "></div>
       <div  style="width:100%; padding:20px 15px;">
       <ul>
           <li><input id="Neem" type="radio" name="sikar" value="Neem Ka Thana"> <label for="Neem">Neema Ka Thana</label></li>
           <li><input id="shrimado" type="radio" name="sikar" value="Shri Madhopur"> <label for="shrimado">Shri Madhopur</label></li>
           <li><input id="danta" type="radio" name="sikar" value="Danta Ramgarh"> <label for="danta">Danta Ramgarh</label></li>
           <li><input id="sikar" type="radio" name="sikar" value="Sikar"> <label for="sikar">Sikar</label></li>
           <li><input id="laxmangarh" type="radio" name="sikar" value="Laxmangarh"> <label for="laxmangarh">Laxmangarh</label></li>
           <li><input id="fatehpur" type="radio" name="sikar" value="Fatehpur"> <label for="fatehpur">Fatehpur</label></li>
       </ul>
       </div>
       </div>
      <input type="text" name="query" id="zipsearch" placeholder="Search By Keywords"  required/>
</form>

How do I get the value of a from its id in JavaScript/jQuery?

bobthedeveloper
  • 3,733
  • 2
  • 15
  • 31
20wa
  • 1
  • 1
  • 4

2 Answers2

1

Use .val()

$('#yourid').val();
John Conde
  • 217,595
  • 99
  • 455
  • 496
0

Also, this is really good:

$('#yourid').is(':checked');

For semantics, this one is more widely used.

Callum Linington
  • 14,213
  • 12
  • 75
  • 154
  • i want to value in hidden type when select sikar and when select Neem Kaa Thana want to value because i want to search query with this field – 20wa Apr 18 '14 at 13:14
  • can you give me proper code with modify my code – 20wa Apr 18 '14 at 13:22
  • This will only work for checking if something is checked, not getting the value. This answers the question you posted, I think you should change your question because this is not what you originally asked for. – Callum Linington Apr 18 '14 at 14:54