StirCrazy Posted August 4, 2006 Share Posted August 4, 2006 I've attached the basics of the Registration page i'm working with.My problem is that when when I use <input type="image"If some of the registation fields are empty and press 'submit' I get an alert but then it refreshes the screen.I don't want it to refresh (coz I lose all the information already entered).When I use <input type="button" this doesn't happen.Does anyone know why it refreshes?Cheers folks,S.C>[code]<script language="javascript"> function check_fields(regform) { errIndicator = 0; for (i = 1; i<11; i++) { if ("" == regform.elements[i].value) { errIndicator = 1; } } if (errIndicator) { alert("Please fill in all fields"); return 1; } if (regform.email.value != regform.email2.value) { alert("E-Mail Confirmation Failed"); return 3; } if (regform.country.value == "no") { alert("You must choose your country"); return 4; } if (regform.agree.checked == false ){alert('Please accept our Terms of service to continue.'); return 5;} regform.submit(); return 0; }</script><form name="regform" action="index.php?page=register3" method="post"><input type="hidden" name="id" value="<?php echo $id; ?>"><div align="center"><!------- CODE HERE ---------><br><center><span class="AcceptTos">I certify that <b>I am a U.K. Resident over the age of 18, and<br>I agree to the</b> <a class="AcceptTos" href="javascript:popup('tos.php')">Terms of Service</a>: <input type="checkbox" value="0" name="agree"></span><br><br><input type="image" src="images/layout/submit.gif" onclick="check_fields(regform);" value=" Sign Up "></center><br></form></div><?php return(0);}[/code] Quote Link to comment Share on other sites More sharing options...
hegtv Posted August 5, 2006 Share Posted August 5, 2006 <input type="image"> acts as a submit button, so when you click on it, the form is being immediately submitted. You could try just using an <img>, with the same onClick parameter as your <input type="image"> OR you could changeonclick="check_fields(regform);"toonclick="check_fields(regform); return false;"and leave it where it is. Either should work fine.Hope that works for you. Quote Link to comment Share on other sites More sharing options...
StirCrazy Posted August 5, 2006 Author Share Posted August 5, 2006 nice one hegtv ~ onclick="check_fields(regform); return false;" works great.S.C> 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.