简体   繁体   中英

asp.net radio button on click event without page load

My problem is pretty simple, but I am not able to fix it.

I have 2 radio buttons and a hidden text label. Once the first radio button is clicked, I want to show the hidden label, and when the second radio button is clicked, I want to hide it again - all this without reloading the page.

I am hoping this can be achieved by JavaScript, but unfortunately I don't know how.

Any help will be appreciated.

Thanks in advance.

Try the following simple example.

 $(document).ready(function() { $('input[type=radio][name=GName]').change(function() { if (this.value == '1') { $("#label").text("Yes"); } else if (this.value == '2') { $("#label").text("No"); } }); });
 <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.1/jquery.min.js"></script> <input type="radio" name="GName" value="1"> Yes</input> <input type="radio" name="GName" value="2"> No</input> <p> <span id="label"> </p>

You can use jQuery to bind an onlick-Event handler

   $('#firstcheckbox').click(function() {
      //code goes here   
   });

   $('#secondcheckbox').click(function() {
      //code goes here   
   });

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM