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?

1
  • 1
    There's a checkbox? I can see one input of type="hidden" and others of type="radio". Commented Apr 18, 2014 at 13:04

2 Answers 2

1

Use .val()

$('#yourid').val();
Sign up to request clarification or add additional context in comments.

Comments

0

Also, this is really good:

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

For semantics, this one is more widely used.

3 Comments

i want to value in hidden type <input type="hidden" value="sikar"> when select sikar and when select Neem Kaa Thana want to value <input type="hidden" value="Neem Kaa Thana"> because i want to search query with this field
can you give me proper code with modify my code
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.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.