Click to See Complete Forum and Search --> : return false


al9000
05-13-2003, 06:08 AM
For some odd reason, return false is not keeping my forms from submitting. My error messages are getting captured and spit out via Alert(), but it seems that the return false is not coming to play. Any ideas where I am being stupid or careless?? I've looked at it too many times so I had to stop in and ask.

<script language=Javascript>
function checkform(a){
var iwebreq = window.document.forms[0].iweb_req.value;
var sys = window.document.forms[0].System.value;
var generic = window.document.forms[0].Generic.value;
var error_stat = 'N';
var err_msg = ' ';
if (iwebreq != null) {
if (((iwebreq.substr(0,1) >= 0) && (iwebreq.substr(0,1) <= 9))
&& ((iwebreq.substr(1,1) >= 0) && (iwebreq.substr(1,1) <= 9))
&& ((iwebreq.substr(2,1) >= 0) && (iwebreq.substr(2,1) <= 9))
&& ((iwebreq.substr(3,1) >= 0) && (iwebreq.substr(3,1) <= 9))
&& ((iwebreq.substr(4,1) >= 0) && (iwebreq.substr(4,1) <= 9))) {
}
else {
var err1 = "Non Numeric iWEB Req Number\n";
err_msg = err_msg + err1;
error_stat = "Y";
}
}
if (iwebreq.length < 5) {
var err2 = "iWEB Req is not a full 5 positions\n";
err_msg = err_msg + err2;
error_stat = "Y";
}
if (error_stat == "Y") {
alert(err_msg);
return false;
}
else {
return true;
}
}
</script>

Fang
05-13-2003, 06:30 AM
You need something like this in your form:
<form id="myform" method="post" onsubmit="return checkform(this);" action="../../cgi-bin/mymailform.pl">
note the return in onsubmit.

SniperX
05-13-2003, 06:35 AM
You dont really need the else {
return true;}
bit. you can just have return true;

on your form check do you have this bit of code onSubmit="return checkform(form);"?
that might be your problem.

Put your full code posting,

but your code listing is very messy(please don't take offence):

try this
function checkform(){
var iwebreq = window.document.forms[0].iweb_req.value;
var sys = window.document.forms[0].System.value;
var generic = window.document.forms[0].Generic.value;
if (iwebreq.length != 0) {//i.e. if there is text there
if (isNaN(iwebreq)) {alert('Non numeric iweb_req number'); return false; }
if (iwebreq.length != 5) {alert('Iweb_req must be five digits long.');return false; }
}
return true;
}

that function should do the job.

al9000
05-13-2003, 06:37 AM
Yep, I was pondering my HTML thinking that must be the problem, and I thought putting onclick versus onsubmit was the issue, but now that I see your post, it rings a bell.

I knew it was something stupid, I prefered careless myself. Thanks!!!

I was missing the RETURN

<form name="build_form1" action="build_add_form2.cfm" method=post onsubmit="checkform()";>

SniperX
05-13-2003, 06:40 AM
i hope you're passing the argument too, but you dont use it,
so it doesn't really matter

al9000
05-13-2003, 06:44 AM
No offense taken at all, I am not a big Jscript fan yet, I also put it together a lot messier than my other code which I tend to take more time with.

I have been learning jscript from O'Reilly's book, I need to find a comprehensive class which is not over my head yet is not snore snore.

Thanks for your help, I can take all the pounding because I know I should be better with this language. I grew up in college with Procedural programming too so it is hard to get used to the new way. Getting there!