Forum Moderators: open
The script is triggered by a graphical submit button. It runs through it's various tests, giving error messages if necessary, and then at the end of the script, it submits (document.form.submit()). The last test it runs is if there are no errors, then assign the action of the form (document.formname.action.value=) to the cgi script on the server. If an error occurs, there is no action, so the page reloads itself. Nothing fancy.
The problem is, the page always reloads itself, even if there are no problems and the action is never assigned and the form never submitted. The last test is being run but it seems to be ignoring the action.
I've tried doing it backwards too. Assigning the form an action, and then changing the action if any of the initial tests come back with an error. That doesn't work either; it just takes me to the cgi script after giving me an error.
It's just a bone simple validator javascript. I'm trying to create all my own scripts instead of using other folks' and I'm not the best, so I may be just doing something wrong. But all the references I've read don't seem to indicate that I'm doing anything wrong. Anybody that is wiser than I in the world of scripting have some advice?
I've been able to modify the action of a form based on several different variables, so the concept is correct.
It could be a simple oddball error.
I have written scripts with and without semi-colons (to my knowledge, it does not make any difference), but, just to cover all my bases, I went in and added semi-colons to this one. No difference.
Thanks for your help. I'm reposting the text file at [gobozeman.com...] . Any other suggestions?
I got it working and this is the page I used.
<HTML>
<HEAD>
<TITLE></TITLE>
<SCRIPT LANG="javascript">
<!--
function formCheck() {
if (document.CopiersInfo.namefield.value == "") {
alert("You forgot to enter your name.");
} else if (document.CopiersInfo.contact[0].status && document.CopiersInfo.phone.value=="") {
alert("We cannot contact you by phone without a phone number.");
} else if (document.CopiersInfo.contact[1].status && document.CopiersInfo.email.value=="") {
alert("We cannot contact you by e-mail without an e-mail address.");
} else if (document.CopiersInfo.contact[2].status && document.CopiersInfo.address.value=="") {
alert("We cannot contact you by mail without your address.");
} else {
document.CopiersInfo.action="";
document.CopiersInfo.redirect.value="";
document.CopiersInfo.recipient.value="";
document.CopiersInfo.subject.value="Request Copier Info";
document.CopiersInfo.submit();
}
}
//-->
</SCRIPT>
</HEAD>
<BODY>
<FORM METHOD=POST NAME="CopiersInfo" ACTION="#">
<INPUT TYPE=HIDDEN NAME="redirect" VALUE="#">
<INPUT TYPE=HIDDEN NAME="recipient" VALUE="#">
<INPUT TYPE=HIDDEN NAME="subject" VALUE="#">
<P><INPUT TYPE=TEXT NAME="namefield" SIZE=20>
<P>Phone<INPUT TYPE=RADIO NAME="contact" CHECKED> <INPUT TYPE=TEXT NAME="phone" SIZE=20>
<P>Email<INPUT TYPE=RADIO NAME="contact"> <INPUT TYPE=TEXT NAME="email" SIZE=20>
<P>Address<INPUT TYPE=RADIO NAME="contact"> <INPUT TYPE=TEXT NAME="address" SIZE=20>
<P><INPUT TYPE=BUTTON VALUE="Click Me" onClick="javascript:formCheck();">
</FORM>
</BODY>
</HTML>