On the 'Edit Profile' page of my eCommerce Wordpress Theme (http://www.projectdisobey.com/disobeyclothing), no error message appears when I do any of the following in the ''New Password' and 'Confirm New Password' text fields:

1. 'New Password' and 'Confirm New Password' do not match.
2. 'Confirm New Password' field is left empty.
3. New password is less than 5 characters.
4. New password is exactly the same as the current password.

This is the script:

<script language="javascript" type="application/javascript">
function chk_form_pw()
{
if(document.getElementById('new_passwd').value == '')
{
alert("<?php _e(ENTER_NW_PW_JS_MSG) ?>");
document.getElementById('new_passwd').focus();
return false;
}
if(document.getElementById('new_passwd').value.length &lt; 4 )
{
alert("<?php _e(ENTER_NW_PW_MIN_JS_MSG) ?>");
document.getElementById('new_passwd').focus();
return false;
}
if(document.getElementById('cnew_passwd').value == '')
{
alert("<?php _e(ENTER_CONFIRMNW_PW_JS_MSG) ?>");
document.getElementById('cnew_passwd').focus();
return false;
}
if(document.getElementById('cnew_passwd').value.length &lt; 4 )
{
alert("<?php _e(ENTER_CONFIRMNW_PW_MIN_JS_MSG) ?>");
document.getElementById('cnew_passwd').focus();
return false;
}
if(document.getElementById('new_passwd').value != document.getElementById('cnew_passwd').value)
{
alert("<?php _e(ENTER_NW_AND_CONFIRM_PW_SAME_JS_MSG) ?>");
document.getElementById('cnew_passwd').focus();
return false;
}
}
</script>

I'd be extremely appreciative if anybody could help me fix the script so that it works as it is meant to. Javascript is not something I'm particularly familiar with...

Thanks in advance!

Could you post also the html and the rest of the javascript?

in this part i don't see any errors,

-Agarsia

Member Avatar for stbuchok

What is the error that is coming up?

@Agarsia: Here's the HTML...

<form name="registerform" class="registerform" action="http://www.projectdisobey.com/disobeyclothing/?page=myaccount&amp;type=editprofile&amp;chagepw=1" method="post">
<div class="myorders ">
    
        <div class="form_row ">
        <label>
        New Password <span class="indicates">*</span></label>      
        <input type="password" name="new_passwd" id="new_passwd"  class="reg_row_textfield" />
          
        </div>
        <div class="form_row ">
        <label>
        Confirm New Password <span class="indicates">*</span> </label>
        <input type="password" name="cnew_passwd" id="cnew_passwd"  class="reg_row_textfield" />
         </div>
</div>
 <input type="submit" name="Update" value="" class="highlight_input_btn fr" onclick="return chk_form_pw();" />
</form>

I'm not sure what you mean when you say to post the rest of the Javascript (I'm a Javascript newbie).

@stbuchok: The problem I am having is that no error messages are coming up. For example, I can type different passwords in the 'New Password' and 'Confirm New Password' fields and no error message comes up.

The problem is, that if you click "Update" the script forwards to "http://www.projectdisobey.com/disobeyclothing/?page=myaccount&amp;type=editprofile&amp;chagepw=1". the chk_form_pw() is not executed at all.
If you want to do this with javascript i would use jQuery/Ajax

or just check the Passwords in the action-file http://www.projectdisobey.com/disobeyclothing/?page=myaccount&amp;type=editprofile&amp;chagepw=1 with php before it is written into the database

In line 16, take out the "onclick" event.

<input type="submit" name="Update" value="" class="highlight_input_btn fr">

Then change your line one to...

<form name="registerform" class="registerform" action="http://www.projectdisobey.com/disobeyclothing/?page=myaccount&amp;type=editprofile&amp;chagepw=1" method="post" onsubmit="return chk_form_pw()">

Thanks for your help Taywin, but I tried this and it hasn't made any difference. Any other suggestions?

Thanks again

Hmm... Change the script tag to...

<script type="text/javascript">

instead and see how it works? Oh and also change any &lt; to < symbol too. I will look through your script code again...

Hmm... Change the script tag to...

<script type="text/javascript">

instead and see how it works? Oh and also change any &lt; to < symbol too. I will look through your script code again...

Thanks! It worked!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.