简体   繁体   中英

radio button show divs on the based on its value

I have a list of radio buttons on the basis of how many id in the mysql table.

when ever clock on the radio then it shows the div details for example

radio buttons

  <input name="value" type="radio" value="facebook" id="facebook"/> facebook
  <input name="value" type="radio" value="google_plus" id="google_plus" /> Google plus
  <input name="value" type="radio" value="orkut" id="orkut" /> orkut

divs

<div id="facebook" style="display:none;">
facebook is one of the most popular social networking website
</div>
<div id="google" style="display:none;">
google plus is the new social network
</div>
<div id="orkut" style="display:none;">
Orkut is a socila networking website powered by google
</div>

when select radio, I need to show divs on the base value="" value of the radio button. the thing is that radio numbers and values will be on the base of mysql data

is there any option to show divs in Jquery ?

if u know help me pls

from what it seems like you're asking you want to know how to show a div via jquery?

.show() method

or .css() method example: $('nameOfYourDiv').css('display','block');

$('input[name="value"]').change(function(){
    var id = $(this).val();
    $('#' + id).show();
});

Hope, this piece of code would be of any help. here is my try to find a solution for your problem :)

$('input:radio').click(function(){
    var idVal = $(this).val();
    $('div').hide();
    $('div[id='+idVal+']').show()
});

please find a working sample here: http://jsfiddle.net/u3AbT/3/

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