treehouse : what would you like to learn today?
Web Design Web Development iOS Development

Radio Button Keeps Resetting on Submit

  • Hey there,

    I've got these two radio buttons, the problem is when you click on the 'Renting' radio button and submit the form the radio buttons reset back to the default 'Buying' button. Any idea how to stop the radio button resetting every time?


    <input name="RentalPeriod" type="radio" value="0" onClick="javascript:configureprices('buy');" checked="checked" />
    <span class="type-radio">Buying</span>

    <input name="RentalPeriod" type="radio" value="3" onClick="javascript:configureprices('rent');" />
    <span class="type-radio">Renting</span>


    Thanks in advance!
  • You call for a javascript event without declaring the script inside your html, is that possible?
  • Realph it goes back because by default checked="checked" is on the Buying - so when the page loads (if it has to reload on submit) you will get that one.

    You could create a hidden field and use the input value to build the page next time round by putting in the checked by php "if else" statement... or something like that :)


    This is for you Eclipse :D

    http://www.w3schools.com/tags/ref_eventattributes.asp
  • Thanks Robskiwarrior
  • Hey Robskiwarrior,

    Thanks for the help but could you possibly elaborate?

    I've taken the 'checked="checked"' off and it's removed the checked Radio Button, what kind of workaround would I have to do if I wanted the button to stay checked on what was selected before the page reloaded?