|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
How CFForm/input interacts with javascript validation
Hi,
I have a page with some javascript (that I copied, as I have no idea how to use JS). The JS tests to see if a value is a valid hex col value. Can someone tell me the best way to make the form code interact with the script. I think onValidate is the one but this doesn't seem to work. I'm a beginner so please be clear. Here is the code: Code:
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<script language="JavaScript">
// *** check the input hex colour value ***
function valhex(){
var validchars="1234567890ABCDEF";
var userclr=document.gethex.usernum.value;
var txtlen = userclr.length;
var usrerr=0
if (txtlen != 6) {usrerr = 1;}
for (count = 0; count<=6; count++){
var digit = userclr.charAt(count).toUpperCase();
if (validchars.indexOf(digit) == -1){usrerr=1;}
}
if (usrerr !=0) {
alert("The value you entered is not correct");
document.gethex.usernum.focus();}
else {ChngClr(userclr);}
}
</script>
<body>
<cfform name="gethex" method="post" action="hex_result.cfm">
<p> #
<cfinput type="text" name="usernum" onValidate="valhex()">
</p>
<p>
<cfinput type="submit" name="Submit" value="Submit">
</p>
</cfform>
</body>
</html>
I've so far had the JS pop up the message if it's not a valid hex but then it actions the next page anyway. I need it to stop if it returns a false value. thanks. |
|
#2
|
|||
|
|||
|
if (usrerr !=0) {
alert("The value you entered is not correct"); document.gethex.usernum.focus(); return false} I think that might work ... there is also a Javascript forum here on devshed, folks there might be better suited to give you an answer. Luck ![]() |
![]() |
| Viewing: Dev Shed Forums > Programming Languages - More > ColdFusion Development > How CFForm/input interacts with javascript validation |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|