I require java script to check characters typed including white spaces in a text area. I am using the form in a cold fusion file. I have tried a function that checks onsubmit of the form but is not working. Please help
kashaziz@yahoo.com
| SitePoint Sponsor |



I require java script to check characters typed including white spaces in a text area. I am using the form in a cold fusion file. I have tried a function that checks onsubmit of the form but is not working. Please help
kashaziz@yahoo.com
do you mean a common validation method?
ie
then in your form:Code:<script language="javascript"> function checkdis(){ if (document.formName.fieldName.value.indexOf(" ")!=-1){ alert("Sorry, you have a space."); document.formName.fieldName.focus();return false } } </script>
Code:<form name="formName" onSubmit="return checkdis()";> <input type="text" name="fieldName"><br> <input type="submit" name="submit"> </form>



I have used a mehtod like that but its not working


OK, what isn't working? And what exactly are you checking for? More details would be helpful. Help us help you.![]()



here is the code:
<html>
<head>
<SCRIPT LANGUAGE="JavaScript">
<!-- This script and many more are available free online at -->
<!-- The JavaScript Source!! http://javascript.internet.com -->
<!-- Begin
function checkchars(form) {
var max=15;
if (form.chars.value.length > max) {
alert("Please do not enter more than 15 characters. Please shorten your entry and submit again.");
return false;
}
else return true;
}
// End -->
</script>
</head>
<body>
<cfif isdefined("form.jobobj") and form.jobobj is not "">
<cfoutput>#form.jobobj# <br></cfoutput>
<cfelse>
<form action="test.cfm" method="post" onsubmit="return checkchars(this)">
<textarea name="jobobj" wrap="ON" cols="50" rows="5" wrap="virtual" ></textarea>
<input type="submit" name="submit" value="submit">
</form>
</cfif>
</body>
</html>


Change the name of the parameter that your function is using (form) to frm, or something else.
function checkchars(frm) {
var max=15;
if (frm.chars.value.length > max) {
alert("Please do not enter more than 15 characters. Please shorten your entry and submit again.");
return false;
}
else return true;
}
And although it works without it, I'd give your form a name in the form tag.
<form name="myForm" action="test.cfm" method="post" onsubmit="return checkchars(this)">



still its not working
<SCRIPT LANGUAGE="JavaScript">
<!-- This script and many more are available free online at -->
<!-- The JavaScript Source!! http://javascript.internet.com -->
<!-- Begin
function checkchars() {
var max=15;
if (document.formName.jobobj.value.length > max) {
alert("Please do not enter more than 15 characters. Please shorten your entry and submit again.");
return false;
}
else return true;
}
// End -->
</script>
</head>
<body>
<cfif isdefined("form.jobobj") and form.jobobj is not "">
<cfoutput>#formName.jobobj# <br></cfoutput>
<cfelse>
<form name="formName" onsubmit="return checkchars(this)">
<textarea name="jobobj" wrap="ON" cols="50" rows="5" wrap="virtual" ></textarea>
<input type="submit" name="submit" value="submit">
</form>
</cfif>
</body>
</html>
the javascript should now work anyway



thanks its working
Bookmarks