Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

IF

Status
Not open for further replies.

Swi

Programmer
Feb 4, 2002
1,963
US
I have the following logic to verify fields contain data before they are submitted:

Code:
function trimAll(sString)
{
	while (sString.substring(0,1) == ' ')
    {
		sString = sString.substring(1, sString.length);
	}
	while (sString.substring(sString.length-1, sString.length) == ' ')
    {
		sString = sString.substring(0,sString.length-1);
	}
	return sString;
}

function newRecord()
	{
		if (trimAll(document.dgridFrm.elements[1].value) == "")
			{
				alert("Please enter a logon id!")
				document.dgridFrm.elements[1].focus();
			}//end if
		else if (trimAll(document.dgridFrm.elements[2].value) == "")
        	{
        		alert("Please enter a password!")
        		document.dgridFrm.elements[2].focus();
        	}//end if
		else if (trimAll(document.dgridFrm.elements[3].value) == "")
        	{
        		alert("Please enter a full name!")
        		document.dgridFrm.elements[3].focus();
        	}//end if
		else if (trimAll(document.dgridFrm.elements[6].value) != "0" && trimAll(document.dgridFrm.elements[6].value) != "1")
        	{
        		alert("Please enter a 1 (yes) or 0 (no) for active!")
        		document.dgridFrm.elements[6].focus();
        	}//end if
		else if (trimAll(document.dgridFrm.elements[7].value) != "0" && trimAll(document.dgridFrm.elements[7].value) != "1")
        	{
        		alert("Please enter a 1 (yes) or 0 (no) for admin!")
        		document.dgridFrm.elements[7].focus();
        	}//end if
        else
        	{
        	    var d1=new Date();
                document.dgridFrm.elements[4].value = d1.getMonth()+1 + '/' + d1.getDate() + '/' + d1.getFullYear();
                document.dgridFrm.action = "save.asp";
        		document.dgridFrm.submit();
        	}//end else
	}//end of newRecord()

This works fine in IE and Safari but in FF it keeps saying my fields need to contain data even though they already do.

Any ideas? Thanks.

Swi
 
Hi

The code you posted works for me in FireFox 9.0.1.

Post the related [tt]form[/tt] too, so we can see what kind of controls you used. Also specify when and how the newRecord() function is called.


Feherke.
 
I thought it had something to do with the TrimAll so I took it off and it passed the first condition but then said the password was empty which is was not.

Swi
 
Can we see your HTML form? If not make sure that the object references are correct.

Make sure you have a form named dgridFrm, and that its second element is your logon id text box etc...

Sounds like the references aren't correct.

----------------------------------
Phil AKA Vacunita
----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.

Web & Tech
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top