?
Solved

javascript validation using cfform

Posted on 2009-05-06
5
Medium Priority
?
424 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 1000 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 1000 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

Learn how to optimize MySQL for your business need

With the increasing importance of apps & networks in both business & personal interconnections, perfor. has become one of the key metrics of successful communication. This ebook is a hands-on business-case-driven guide to understanding MySQL query parameter tuning & database perf

Question has a verified solution.

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

In our day to day coding, how many times have we come across a necessity to check whether a URL is a broken link or not? For those of you that answered countless and are using ColdFusion like myself, then this article is for you.  It will show yo…
Lease-to-own eliminates the expenditure of hardware replacement and allows you to pay off the server over time. Usually, this is much cheaper than leasing servers. Think of lease-to-own as credit without interest.
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…

765 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