Friday, May 17, 2024
188
rated 0 times [  191] [ 3]  / answers: 1 / hits: 30370  / 9 Years ago, tue, june 9, 2015, 12:00:00

I have HTML CODE below:





$('input[type=radio]').click(function(){

if($(this).attr(value)==ABC){
$(.Box).hide('slow');
}
if($(this).attr(value)==PQR){
$(.Box).show('slow');

}
});

<table>
<tr>
<td align=left height=45>

<input type=radio class=radioBtn name=Radio
id=Radio value=ABC required>
ABC

<input class=radioBtn type=radio name=Radio
id=Radio value=PQR required>
PQR

<div class=Box style=display:none>Text</div>
</td>
</tr>
</table>





All above code is working fine & properly. But my issue is that when I checked by default PQR then the Box div should display with clicking radio button. What wrong in my code or what changes it need..??


More From » radio-button

 Answers
27

you need to trigger the click



$(document).ready(function () {

$('input[type=radio]').click(function () {
if ($(this).attr(value) == ABC) {
$(.Box).hide('slow');
}
if ($(this).attr(value) == PQR) {
$(.Box).show('slow');

}
});

$('input[type=radio]').trigger('click'); // trigger the event
});


DEMO


[#66274] Saturday, June 6, 2015, 9 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
victorr

Total Points: 193
Total Questions: 86
Total Answers: 105

Location: Pitcairn Islands
Member since Thu, Jun 24, 2021
3 Years ago
victorr questions
Fri, Nov 13, 20, 00:00, 4 Years ago
Sat, Jul 25, 20, 00:00, 4 Years ago
Thu, Jun 11, 20, 00:00, 4 Years ago
;