gek
gek

Reputation: 125

Change of link button name based on radio value

I have a table with a selection of input radio buttons. 2 of the radio input buttons have value ="P2" or "P1" and the rest values starting with S as you can see below

<input id="test" name="purchaseChoice" class="radio" onclick="togglePrices(false);" type="radio" value="P2"/>
<input id="test" name="purchaseChoice" class="radio" onclick="togglePrices(true);" type="radio" value="P1"/>


<input id="test" name="purchaseChoice" class="radio" onclick="togglePrices(true);" type="radio" value="S111"/>
<input id="test" name="purchaseChoice" class="radio" onclick="togglePrices(false);" type="radio" value="S112"/>
<input id="test" name="purchaseChoice" class="radio" onclick="togglePrices(true);" type="radio" value="S131"/>
<input id="test" name="purchaseChoice" class="radio" onclick="togglePrices(false);" type="radio" value="S132"/>
<input id="test" name="purchaseChoice" class="radio" onclick="togglePrices(true);" type="radio" value="S121"/>
<input id="test" name="purchaseChoice" class="radio" onclick="togglePrices(false);" type="radio" value="S122"/>
<a href='javascript: submitform("subsOptionform")' tabindex="14" class="right button blue">Subscribe</a>

I would like to have the label of the a link change from Subscribe to Buy credits when the 2 first radio buttons are selected.

Any help appreciated.

Thanks

Upvotes: 0

Views: 519

Answers (1)

wanovak
wanovak

Reputation: 6127

First you will need to change the IDs of your inputs to unique values or nothing is guaranteed to work.

Next, try putting this in your $(document).ready(function(){:

$('.radio').change(function(){
    if($(this).attr('value') === 'P1' || $(this).attr('value') === 'P2'){
        $('.blue').text('Buy credits');
    }else{
        $('.blue').text('Subscribe');
    }
});

Upvotes: 1

Related Questions