ColdFusion Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming Languages - MoreColdFusion Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old January 25th, 2005, 09:54 AM
wonderlandh wonderlandh is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2005
Location: Nottingham UK
Posts: 60 wonderlandh User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 7 h 48 m 31 sec
Reputation Power: 4
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.

Reply With Quote
  #2  
Old January 26th, 2005, 09:15 AM
VelvettFogg VelvettFogg is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2004
Posts: 34 VelvettFogg User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 3 h 13 m 46 sec
Reputation Power: 4
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

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming Languages - MoreColdFusion Development > How CFForm/input interacts with javascript validation


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 4 hosted by Hostway