Solved

javascript validation using cfform

Posted on 2009-05-06
5
420 Views
Last Modified: 2013-12-24
I have the following but it doesn't work properly.  It still submits.  it should pull up the alert but not submit the form data.  any ideas?
<script language="JavaScript" type="text/javascript">
	function validatePassword() {
		{
			if (document.changepwd.newPassword.value != document.changepwd.confirmPassword.value)
			alert("Your new passwords must match. Please try again.");
			return false;
		}
return true;
	}
</script>
 
<cfform name="changepwd" action="" method="POST" onsubmit="validatePassword()">
	<div class="">Username: <cfinput type="Text" name="username" validateat="onSubmit" message="You must enter a valid username." validate="email" autosuggestminlength="8" required="Yes" visible="Yes" enabled="Yes" showautosuggestloadingicon="True" typeahead="No" maxlength="50"></div>
	<div class="">New password: <cfinput type="Text" name="newPassword" validateat="onSubmit" message="You must enter a valid password." maxlength="16" required="Yes" visible="Yes" enabled="Yes" showautosuggestloadingicon="True" typeahead="No"></div>
	<div class="">Confirm password: <cfinput type="Text" name="confirmPassword" validateat="onSubmit" message="You must enter a valid password." maxlength="16" required="Yes" visible="Yes" enabled="Yes" showautosuggestloadingicon="True" typeahead="No" onchange="javascript:window.alert(form.newPassword.value + ' ' + form.confirmPassword.value);"></div>
	<cfif isDefined("form.submit")>
	do something..
	</cfif>
</cfform>

Open in new window

0
Comment
Question by:COwebmaster
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
5 Comments
 
LVL 36

Accepted Solution

by:
SidFishes earned 250 total points
ID: 24319897
just chnage your script to this

<script language="JavaScript" type="text/javascript">
        function validatePassword() {
               
                        if (document.changepwd.newPassword.value != document.changepwd.confirmPassword.value)
                        {alert("Your new passwords must match. Please try again.");
                        return false;}
                        else
                  {
                        return true;                        
                }

        }
</script>
0
 
LVL 63

Expert Comment

by:Zvonko
ID: 24320376
check this:
<script language="JavaScript" type="text/javascript">
        function validatePassword(theForm) {
                {
                        if (theForm.newPassword.value != theForm.confirmPassword.value){
                          alert("Your new passwords must match. Please try again.");
                          return false;
                        }
                }
                return true;
        }
</script>
<cfform name="changepwd" action="" method="POST" onsubmit="return validatePassword(_CF_this)">
        <div class="">Username: <cfinput type="Text" name="username" validateat="onSubmit" message="You must enter a valid username." validate="email" autosuggestminlength="8" required="Yes" visible="Yes" enabled="Yes" showautosuggestloadingicon="True" typeahead="No" maxlength="50"></div>
        <div class="">New password: <cfinput type="Text" name="newPassword" validateat="onSubmit" message="You must enter a valid password." maxlength="16" required="Yes" visible="Yes" enabled="Yes" showautosuggestloadingicon="True" typeahead="No"></div>
        <div class="">Confirm password: <cfinput type="Text" name="confirmPassword" validateat="onSubmit" message="You must enter a valid password." maxlength="16" required="Yes" visible="Yes" enabled="Yes" showautosuggestloadingicon="True" typeahead="No" ></div>
        <cfif isDefined("form.submit")>
        do something..
        </cfif>
<input type="submit" >
</cfform>

Open in new window

0
 
LVL 63

Assisted Solution

by:Zvonko
Zvonko earned 250 total points
ID: 24320404
This two extra lines brings more convenience:
<script language="JavaScript" type="text/javascript">
        function validatePassword(theForm) {
                {
                        if (theForm.newPassword.value != theForm.confirmPassword.value){
                          alert("Your new passwords must match. Please try again.");
                          theForm.confirmPassword.select();
                          theForm.confirmPassword.focus();
                          return false;
                        }
                }
                return true;
        }
</script>
<cfform name="changepwd" action="" method="POST" onsubmit="return validatePassword(_CF_this)">

Open in new window

0
 

Author Comment

by:COwebmaster
ID: 24339914
how can I also ensure that the password field is equal or more than 6 characters using cfform?
0
 
LVL 63

Expert Comment

by:Zvonko
ID: 24342783
How can we ensure this question will not get additional questions appended?
0

Featured Post

Free NetCrunch network monitor licenses!

Only on Experts-Exchange: Sign-up for a free-trial and we'll send you your permanent license!

Here is what you get: 30 Nodes | Unlimited Sensors | No Time Restrictions | Absolutely FREE!

Act now. This offer ends July 14, 2017.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Have you ever sent email via ColdFusion and thought of tracking this mail to capture the exact date and time when the message was opened ?  If yes, then this article is for you ! First we need a table user_email with columns user_id , email , sub…
When it comes to security, close monitoring is a must. According to WhiteHat Security annual report, a substantial number of all web applications are vulnerable always. Monitis offers a new product - fully-featured Website security monitoring and pr…
In this video, viewers are given an introduction to using the Windows 10 Snipping Tool, how to quickly locate it when it's needed and also how make it always available with a single click of a mouse button, by pinning it to the Desktop Task Bar. Int…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…

688 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question