Jump to content

Change submit button text based on radio button selected


Recommended Posts

I'm looking to change a submit buttons text based on which radio button is checked.

 

 

Here's the form data:

 

<div class="register_membership_type_position">
<span class="register_membership_type_title">Membership Type:</span>
<span class="register_membership_type_basic_position"><input type="radio" value="basic" name="register_membership_type" id="register_membership_type_basic" class="register_membership_type_basic" onchange="changeButton('basic');" checked="checked" /> <label for="register_membership_type_basic"><span class="register_radio_text">Basic</span></label></span>
<span class="register_membership_type_premium_position"><input type="radio" value="premium" name="register_membership_type" id="register_membership_type_premium" class="register_membership_type_premium" onchange="changeButton('premium');" /> <label for="register_membership_type_premium"><span class="register_radio_text">Premium</span></label></span>
<span class="register_membership_type_platinum_position"><input type="radio" value="platinum" name="register_membership_type" id="register_membership_type_platinum" class="register_membership_type_platinum" onchange="changeButton('platinum');" /> <label for="register_membership_type_platinum"><span class="register_radio_text">Platinum</span></label></span>
<span class="learn_more_position">(<a href="/signup?memberships">Learn More About Membership Types</a>)</span>
</div>

<p class="register_form_position register_submission">
<input type="submit" value="Sign Up" class="register_button_position" id="submit_button" />
</p>

 

 

Here's the javascript I've been trying, but haven't had much luck.

function changeButton(selection)
{
selection.charAt(0).toUpperCase() + selection.slice(1);
el = document.getElementById(submit_button);
el.value = 'Sign Up for '+selection+' Membership';
}

Link to comment
Share on other sites

Works perfectly, thanks.

 

Now is there anyway to make it so it loads "Sign Up for Basic Membership" right when the page loads?

 

I have the button set just to "Sign Up" for users without Javascript enabled.

 

Any way to use window.onload=changeButton(basic); (tried this and doesn't work) or something like that?

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.