Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

javascript validation using cfform

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

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Question has a verified solution.

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

Most ColdFusion developers get confused between the CFSet, Duplicate, and Structcopy methods of copying a Structure, especially which one to use when. This Article will explain the differences in the approaches with examples; therefore, after readin…
Article by: kevp75
Hey folks, 'bout time for me to come around with a little tip. Thanks to IIS 7.5 Extensions and Microsoft (well... really Windows 8, and IIS 8 I guess...), we can now prime our Application Pools, when IIS starts. Now, though it would be nice t…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
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…

610 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