PDA

View Full Version : Stopping a for submit with javascript


eyeRmonkey
04-12-2003, 01:00 PM
Ok, I have a form that lets you log into the members only section. It is in a frame. I have a system set up so when you click login and you havn't entered anything you get an alert messag that says please enter text. But when I test it and click submit on it gives the alert and then reaload the frame but it takes up the whole page. I also don't want it to have reload either. Oh ya and the script executes when you submit the form.. Any help.

dank
04-12-2003, 01:20 PM
http://javascript.internet.com/forms/required-fields.html

Dan

eyeRmonkey
04-12-2003, 04:19 PM
That didnt help much. I know how to make the alert when they didnt put in the required field but I need to know how to stop the page from reloading itself. I don't know why it does.

eyeRmonkey
04-12-2003, 04:38 PM
OK actually that did help but I already knew the return false thing. What I need to do is stop the page from reloading. At first it was realoading and taking up the entire frameset instead of its section but now the page just comes up with the error message and reloads. I need to stop it from reloading.%)

dank
04-12-2003, 04:59 PM
When you say the frame is reloading, do you mean on a successful submit or even when data is missing on submission? If it is only after a successful submit, then I don't believe there's anything you can really do about that. That's just the way forms work... It has to go somewhere upon submission, otherwise the form doesn't get processed. Can't say I understand why you would be doing that in a frame...

Dan

eyeRmonkey
04-13-2003, 12:32 PM
On a successful submit it reloads but come up with a table stating their member name and giving them the option to logout. When they are missing something from the form then it come up with the alkert and reloads even when I put in return false. Im thinking that is the only way to stop it from reloading. I think I will just have to rewrite some of my scripts because that must be what is causing it (conflicting scripts). I am doing it in a frame so members have an easy way to login.

dank
04-13-2003, 01:16 PM
When they are missing something from the form then it come up with the alkert and reloads even when I put in return false.
You've probably got something slightly wrong in your code then. That shouldn't be happening... I would double check that you haven't added anything in incorrect relative to the example script. If in doubt, install just that example code into your frame and see if it works properly, then start adjusting it to your own needs.

Dan

eyeRmonkey
04-13-2003, 04:21 PM
Hey I just noticed you from Salem. Im from Oregon City. Any way ya I would start form scratch with the example script but it would mean me just starting over. Its not a simple script i ahve been working on it for quite a while. I think I might be forced to start over any way. It is getting really complex and it might not work on helf the browsers.

Confused
04-14-2003, 11:29 PM
return false;

that is your answer!

first of all ... make sure you refernce your script to check for form input on the submission .... this can be done a number of ways ....

then when checking you forms fields ....


if($username=="" || $password==""){//or what ever checks you are doing
alert('hey you fool, you must actually log in to be logged in!');
return false;
}else{
return true;
}

I usually replace the submit button with a regular button object then use the onclick handler to check with the script for data validity then use


if($username=="" || $password==""){
alert('some not so rude message, maybe?');
return false;
}else{
document.forms[0].submit();//you may use the form name too, of course
}

another point is to be SURE to check the data validity of the server ANYWAY!
You must still assume that you have invalid or no data when the form is submitted. This is for security reasons. This JS type validation is really best used to ensure that if data isn't input or is in the wrong format the user doesn't have to re-type it all....using the return false doesn't clear the fields.....

eyeRmonkey
04-15-2003, 11:06 PM
what is $name and $password?