xxsunshinegodxx Posted February 3, 2011 Share Posted February 3, 2011 I have got a registration form requiring usual, name, address, username, email etc Later on toward the end of the form it asks for country and then state. The country and states are stored in a database and the form queries the database for the states stored according to country. Trouble is that everytime I click on a country it refreshes the whole page and loses all the data that had been types in thus far...not only that but it doesn't select the state, just defaults back to please select a country. The coding relevant to the form reads below. <tr height="20"> <td class="tb_small"><b>Country :</b></td> <td> <select name="ud_cid" id="ud_cid" onChange="form1.submit(); "class="textfield"> <? getCountry($ud_cid); ?> </select></td> </tr> <tr height="20"> <td class="tb_small"><b>State :</b></td> <td> <select name="ud_sid" id="ud_sid" class="textfield"> <? getState($ud_cid); ?> </select></td> I am guessingt hat it has got to do with the submit perhaps being similar to the submit button that I use to post the form with??? <br><input name="action" type="submit" class="btn" value="Join"><br><br> </td> However, this is really frustrating and holding me back. ANy help on this would be greatly appreciated. Many thanks Quote Link to comment https://forums.phpfreaks.com/topic/226605-onchangeform1submit-help-keeps-refreshing-and-losing-data/ Share on other sites More sharing options...
Maq Posted February 3, 2011 Share Posted February 3, 2011 Moving to JS section, also, please use tags next time. Quote Link to comment https://forums.phpfreaks.com/topic/226605-onchangeform1submit-help-keeps-refreshing-and-losing-data/#findComment-1169552 Share on other sites More sharing options...
denno020 Posted February 4, 2011 Share Posted February 4, 2011 So is the onChange event to grab the states that are in the given country? You will need to add some PHP so that when the country is chosen (and the form is subsequently submitted), the PHP checks for submission, and then builds a new form that has all the posted variables pre-loaded into the form fields. so for example, the first_name field will become <input type="text" name="first_name" size="25" value="<?php $_POST["first_name"] ?>"> Hope that helps.. Denno Quote Link to comment https://forums.phpfreaks.com/topic/226605-onchangeform1submit-help-keeps-refreshing-and-losing-data/#findComment-1169676 Share on other sites More sharing options...
brianlange Posted February 4, 2011 Share Posted February 4, 2011 Can you post a url? You might have to do an ajax call for the location info. Quote Link to comment https://forums.phpfreaks.com/topic/226605-onchangeform1submit-help-keeps-refreshing-and-losing-data/#findComment-1169951 Share on other sites More sharing options...
xxsunshinegodxx Posted February 4, 2011 Author Share Posted February 4, 2011 Thanks for the comments guys. I know that I need to update the code in some ways as the site was designed in 2003 and so needs to come up to scope with the latest php version but this is bugging me as I am stuck. Url is http://newquayuncovered.com/register/index.php I am guessing the onchange is to get the states from the database but instead of just populating the next dropdown box with the states it is refreshing the whole page instead. Quote Link to comment https://forums.phpfreaks.com/topic/226605-onchangeform1submit-help-keeps-refreshing-and-losing-data/#findComment-1170061 Share on other sites More sharing options...
Pikachu2000 Posted February 4, 2011 Share Posted February 4, 2011 <input type="text" name="first_name" size="25" value="<?php $_POST["first_name"] ?>"> You need an echo in there . . . <input type="text" name="first_name" size="25" value="<?php echo $_POST["first_name"]; ?>"> Quote Link to comment https://forums.phpfreaks.com/topic/226605-onchangeform1submit-help-keeps-refreshing-and-losing-data/#findComment-1170062 Share on other sites More sharing options...
denno020 Posted February 5, 2011 Share Posted February 5, 2011 You need an echo in there . . . Oops. Thanks for the correction. Denno Quote Link to comment https://forums.phpfreaks.com/topic/226605-onchangeform1submit-help-keeps-refreshing-and-losing-data/#findComment-1170067 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.