tags:

views:

68

answers:

4

I have 3 radiobutton on my page. There are 3 buttons also on the same page. i want to show different buttons when each is clicked.

<input id="Radio1" type="radio" name="grp1" class="abc" />
<input id="Radio2" type="radio" name="grp1" class="abc" />
<input id="Radio3" type="radio" name="grp1" class="abc" />

Update: There is only one button to be shown corresponding to each radio button..For eg: If Radio1 is clicked show Button 1, if Radio 2 is clicked show Button 2 and so on

A: 

Are you trying

Click()

or maybe

change()

should work :)

Rin
+2  A: 
$(function() { // at dom ready
  $('input.abc').change(function() { // on radio's change event
    $('.buttons-to-hide-class').hide(); // hide buttons
    $('#button-to-show-id').show(); // show desired button
  });
});
Jeff Ober
There is only one button to be shown corresponding to each radio button..For eg: If Radio1 is clicked show Button 1, if Radio 2 is clicked show Button 2 and so on
KJai
+1  A: 
$('#Radio1').click(function() { $('#button1').value = 'new value'; });

something like that

Nicky De Maeyer
I think this is the answer the OP is actually looking for; instead of creating 3 buttons, create 1 and change the action based on the radio button selected.
beggs
+1  A: 

I think what Nicky De Maeyer is suggesting is better, and I'm sure there is a better way to code this way, but:

Script

$(function() {
    //hide all the buttons when the page loads
    $('.def').hide(); 
    //add an onchange function to each radiobutton
    $('input.abc').change(function() { 
        //hide all the other buttons
        $('.def').hide(); 
        //construct the ID of the button to show and show it
        $('#' + this.id + '-Button').show()
        });
    });

HTML

<input id="Radio1" type="radio" name="grp1" class="abc" />
<input id="Radio2" type="radio" name="grp1" class="abc" />
<input id="Radio3" type="radio" name="grp1" class="abc" />

<input id="Radio1-Button" type="button" value="1" class="def" ></input>
<input id="Radio2-Button" type="button" value="2" class="def" ></input>
<input id="Radio3-Button" type="button" value="3" class="def" ></input>
beggs