HDFilmMaker2112 Posted May 29, 2012 Share Posted May 29, 2012 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'; } Quote Link to comment Share on other sites More sharing options...
PravinS Posted May 29, 2012 Share Posted May 29, 2012 Use this JS function function changeButton(selection) { var t = selection.charAt(0).toUpperCase() + selection.slice(1); el = document.getElementById('submit_button'); el.value = 'Sign Up for '+t+' Membership'; } Quote Link to comment Share on other sites More sharing options...
HDFilmMaker2112 Posted May 29, 2012 Author Share Posted May 29, 2012 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? Quote Link to comment Share on other sites More sharing options...
PravinS Posted May 29, 2012 Share Posted May 29, 2012 put this at the end of the page <script language="javascript" type="text/javascript">changeButton('basic');</script> Quote Link to comment Share on other sites More sharing options...
HDFilmMaker2112 Posted May 29, 2012 Author Share Posted May 29, 2012 put this at the end of the page <script language="javascript" type="text/javascript">changeButton('basic');</script> Excellent. Thanks. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.