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 TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

onSubmit not activating Validation

Status
Not open for further replies.

pandapark

Technical User
Jan 29, 2003
92
GB
I have the following code which works apart from the validation is not called i.e. onSubmit="return validate(document.richeytest);"
I have to have it as a string because I am trying to incorporate it within an external web package
the RepairsValidation.js file is shown at the end of this page

thanks
kim

strHead = "<SCRIPT language=""Javascript"" SRC=""js/RepairsValidation.js""></script>"
strHead = "<SCRIPT LANGUAGE=""javascript"">"
strHead = strHead & "function validate(formToValidate) {"
strHead = strHead & "var ErrorMsg = """";"
strHead = strHead & "ErrorMsg += validateMandatoryText(formToValidate.elements(""rhtest""));"
strHead = strHead & "if(ErrorMsg!="""")"
strHead = strHead & "{"
strHead = strHead & "ErrorMsg = ""The following errors occurred with your submission\n\n"" + ErrorMsg;"
strHead = strHead & "alert(ErrorMsg);"
strHead = strHead & "return false;"
strHead = strHead & "}"
strHead = strHead & "return true;"
strHead = strHead & "}"
strHead = strHead & "</script>"

strOutput = strOutput & "<form name=""richeytest"" method=""POST"" onSubmit=""return validate(document.richeytest);"" action=""main.asp"">" & chr(13)
strOutput = strOutput & "<input name=""rhtest"" type='text' size=""2"">" & chr(13)
strOutput = strOutput & "<input type=""Submit"" value=""Submit"">" & chr(13)
strOutput = strOutput & "<input type=""reset"" value=""reset"">" & chr(13)
strOutput = strOutput & "</form>" & chr(13)

-----------------------------------------
RepairsValidation.js file as below

function checkComplete(checkField)
{
var checkFieldName;
var checkFieldValue;

if(typeof(checkField) == "string")
{
checkFieldName = "Text";
checkFieldValue = checkField;
}
else
{
checkFieldName = checkField.name;
checkFieldValue = checkField.value;
}

if(checkFieldValue.length == 0)
{
return "You have not completed the " + checkFieldName + " field\n";
}
else
{
return "";
}
}


function validateMandatoryText(textField)
{
var strComp = checkComplete(textField);
if (strComp == "")
{
return validateText(textField);
}
else
{
return strComp;
}
}

 
Can you post the parsed html by your browser? (view source) It will make things easier to debug.

-kaht

banghead.gif
 
Thanks kaht

I've realised i didn't have strHead = strHead & on the second line of building up the strHead string - it works ok now
thanks anyway

kim
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top