0

I'm making a form to change the password. I ask for the current password and then there are two fields to put the new password. I have two problems: First: I need to check if the two fields of the new password are equal.I used onsubmit to check that.If they are the same, submit.If not it should show a message saying something.The problem is that it doesn't display.This is the code:

function checkform(){
    var pass=myForm.pass.value;
    var new=myForm.new.value;
    var new=myForm.new2.value;
    if(new!=new2){
       document.getElementById("message").style.display='block';
       document.getElementById("pass").value=" ";
       document.getElementById("new").value=" ";
       document.getElementById("new2").value=" ";
       return false;
     }else{
         return true;
     } 
}

When I insert diferent new passwords it still submits, but if I delete that document.getElementById it doesn't submit. Second problem: I have a php page (not using frameworks, just php) that is a class.When I want to acess a function of that class all I need to do is

include("class.php");
$my = new the_class(); $response= $my->check();`

The check() function retrives the password, so then I can check if the value from the field pass is the same as the $response.But how can I put this on the function checkform()? It doesn't work this way.

sonam gupta
  • 775
  • 6
  • 17
Mar10Bel
  • 41
  • 2
  • 6
  • Might be a copy and paste problem but you are setting the same variable `new` to both your `new` and `new2` values. – theduck Jun 30 '15 at 11:20
  • Also, `new` is a reserved keyword in JavaScript so you shouldn't be naming a variable that – theduck Jun 30 '15 at 11:21
  • http://stackoverflow.com/questions/3350247/how-to-prevent-form-from-being-submitted use this link to solve your problem – Viswanath Polaki Jun 30 '15 at 11:21
  • I had already seen that post.If i put alert() instead of that document.getelementbyid it works.What i don't understand it's why if i put the document.getelementbyid it doesn't work anymore – Mar10Bel Jun 30 '15 at 11:32

2 Answers2

1

Don't take the variable name as new its a keyword it is reserved for creating an instance, so better take some other name to the variable and you may get what you're looking for.

Scott Anderson
  • 1,363
  • 1
  • 10
  • 19
0
    **You Try below code**   

   function checkform(){
        var pass=myForm.pass.value;
        var new=document.getElementById("new").value();
        var new=document.getElementById("new2").value();
        if(new!=new2){
        document.getElementById("message").style.display='block';
        document.getElementById("pass").value=" ";
        document.getElementById("new").value=" ";
        document.getElementById("new2").value=" ";
            return false;
        }else{
            return true;
        } 
    }