Javascript Submit button won't execute if validation

Good Day,

I have the below javascript saved as a JS resource and attached to a form. When the js function f_Submit is executed it will throw the first alert outside of any validation but it will not enter into any of my validation statements. I cannot figure out what is wrong with this code or my settings. Any pointers would be appreciated. The button is setup as follows:

<INPUT TYPE=“image” SRC=“submit.gif” VALUE=“SubmitFormWeb”

NAME=“SubmitFormWeb” onClick=“f_Submit()”>

The Javascript is as follows:

function f_Submit()

{

var f = document.forms[0];

alert(f.ProcessName.value);



if (document.forms[0].LogonID.value != "")  

 	{ 

		alert ("Please enter your LogOn ID");

		f.LogonID.focus();

 		f.LogonID.select(); 

		return false;

	}

if (document.forms[0].LogonID.value=="")  

 	{ 

		alert ("Please enter your LogOn ID");

		f.LogonID.focus();

           f.LogonID.select(); 

		return false;

	}

if ( f.User_Name.value=="" )  

 	{ 

		alert ("Please enter your Name.");

		f.User_Name.focus();

           f.User_Name.select(); 

		return false;

	}

if ( f.PC_Status.value=="" )  

 	{ 

		alert ("Please enter the status of this request, Open for new requests.");

		f.PC_Status.focus();

		f.PC_Status.select(); 

		return false;

	}

f.submit();

return true;

}

This script should error our regardless based on the first to conditions, yet it fails to no matter what.

Please help… I am going nutz today…

Subject: Javascript Submit button won’t execute if validation

JS is case-dependent. Check (with “View Source”) that the names of the inputs in the JS correct. Also, you don’t have a second in there do you?

Subject: RE: Javascript Submit button won’t execute if validation

Unfortunately it isn’t a second form same name or a form named twice… As for the case sensitivity, everything is matching in the source and in notes…

It just looks like it won’t go into the if statements…

Subject: RE: Javascript Submit button won’t execute if validation

Actually, there is no need for the else statements because you are returning false in the block. Only one will ever run anyway.Also, javascript can be somewhat quirky when submitting in this way.

Probably the best way to handle it is to change your button code to simply do

@command([filesave]); @command([fileclosewindow])

and then call the function below in your onSubmit event (or move the code directly into the event if this is the only place you use it)… This should ensure that the event runs correctly every time.

function f_Submit()

{

var f = document.forms[0];

alert(f.ProcessName.value);

alert(f.LogonID.value) // always a good idea and I recommend, during testing at least, that you place an alert like this one before each conditional. Show the value before you test it… this also lets you know where you are in your code… in case it breaks. I usually place alerts with numeric counters in long js functions for this very purpose… helps narrow down where to look when there are problems.

if (f.LogonID.value != “”)

{

alert (“Please enter your LogOn ID”);

f.LogonID.focus();

f.LogonID.select();

return false;

}

if (f.LogonID.value==“”)

{

alert (“Please enter your LogOn ID”);

f.LogonID.focus();

f.LogonID.select();

return false;

}

if ( f.User_Name.value==“” )

{

alert (“Please enter your Name.”);

f.User_Name.focus();

f.User_Name.select();

return false;

}

if ( f.PC_Status.value==“” )

{

alert (“Please enter the status of this request, Open for new requests.”);

f.PC_Status.focus();

f.PC_Status.select();

return false;

}

f.submit();

return true;

}

Subject: RE: Javascript Submit button won’t execute if validation

I determined that for some reason the JS could not see the LogonID which is computed when composed with a default value of remote_user and yes there is a remote_user field on the form. To make the JS see the field I added the old standby of which did not rectify the issue??

Subject: RE: Javascript Submit button won’t execute if validation

LogonID has to be an editable field for this code to work correctly. A Computed field can’t be accessed in this manner (it is not an “input” type field so you can’t set focus on it or treat it as an input item in html.

Subject: RE: Javascript Submit button won’t execute if validation

But by wrapping the field with the it worked fine, other than buggering up my notes version by adding "> to the end of the cell value when displayed.

But we covered that off over in this thread,

http://www-10.lotus.com/ldd/nd6forum.nsf/ShowMyTopicsAllThreadedweb/334c7f2b7db7b6728525728f00554a90?OpenDocument

Thanks Joel

Subject: RE: Javascript Submit button won’t execute if validation

I determined that for some reason the JS could not see the LogonID which is computed when composed with a default value of remote_user and yes there is a remote_user field on the form. To make the JS see the field I added the old standby of which did not rectify the issue??

Subject: Javascript Submit button won’t execute if validation

try adding the else if’s and the else…

function f_Submit()

{

var f = document.forms[0];

alert(f.ProcessName.value);

if (document.forms[0].LogonID.value != “”)

{

alert (“Please enter your LogOn ID”);

f.LogonID.focus();

f.LogonID.select();

return false;

}

else if (document.forms[0].LogonID.value==“”)

{

alert (“Please enter your LogOn ID”);

f.LogonID.focus();

f.LogonID.select();

return false;

}

else if ( f.User_Name.value==“” )

{

alert (“Please enter your Name.”);

f.User_Name.focus();

f.User_Name.select();

return false;

}

else if ( f.PC_Status.value==“” )

{

alert (“Please enter the status of this request, Open for new requests.”);

f.PC_Status.focus();

f.PC_Status.select();

return false;

}

else

{

f.submit();

return true;

}

}

Subject: RE: Javascript Submit button won’t execute if validation

I tried it to no avail, the code still skips past all the if statements to the final submit.

Anyone one else ever have this issue?