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

executing a method while form submit

Status
Not open for further replies.

daka94

Programmer
Apr 27, 2001
33
US
Hai,
here i am using some function to validate special characters like single quotes given in input.
it is not working.please help me .But it is working fine when i put every thing in one function.
here code is given below
my Java Script file is
testscript.JS

function validate(formObject) {
if(specialCharacters(formObject.field_1))
{
alert("some special character are there which does not accept as input")
form.textObject.focus();
return false;
}

return true;
}

function specialCharacters(textObject) {

var objectValue = textObject.value;
var objectLength = objectValue.length;
var extraChars=&quot;#+/-.,?$&*():~`\;_ <>=&quot;;
var search;

for(var i = 0; i != objectLength; i++) {
aChar = objectValue.substring(i,i+1);
aChar = aChar.toUpperCase();
search = extraChars.indexOf(aChar);
if(search == -1 && (aChar < &quot;A&quot; || aChar > &quot;Z&quot;) && (aChar < &quot;0&quot; || aChar > &quot;9&quot;))
return true;
else
return false;

}
}

and my page is

<html>
<head>

<title>Test Page</title>

<SCRIPT LANGUAGE=&quot;JavaScript1.2&quot; SRC=&quot;testscript.JS&quot;></SCRIPT>


</head>

<body>
<form action=&quot;test.jsp&quot; name=&quot;test&quot; method=&quot;post&quot; onsubmit=&quot;return validate(this)&quot;>
field_1:<input name =&quot;field_1&quot; size=&quot;30&quot; maxlength=&quot;30&quot;>
<input type=&quot;submit&quot; name=&quot;submit&quot; value=&quot;submit&quot;>

</form>
</body>
</html>

thank u in advance
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top