-1

I am trying that, when I click on a button it shows a alert message and go to another page

function password_change_function() {
  var x = document.getElementById("password_change").value;
  alert("Password is changed");
  window.location.assign("viewprofile.php");
}
<form>
  <table>
    <tr>
      <td><strong>Current Password</strong></td>
      <td><strong>:</strong></td>
      <td><input type="password" name="currentpassword" value="ratul@aiub" /></td>
    </tr>
    <tr>
      <td><strong>New Password</strong></td>
      <td><strong>:</strong></td>
      <td><input type="password" name="newpassword" value="kumar@ai" /></td>
    </tr>
    <tr>
      <td><strong>Retype New Password</strong></td>
      <td><strong>:</strong></td>
      <td><input type="password" name="retypepassword" value="kumar@ai" /></td>
    </tr>
  </table>
  <p align="center"><input id="password_change" type="submit" value="Submit" onclick="password_change_function()" /></p>
</form>

the main problem is ,it shows the alert message but page not changed

Sandy B
  • 113
  • 1
  • 15

3 Answers3

1

you might want to try switching the last two statements around like this

window.location.assign("viewprofile.php");
alert("Password is changed");} // End of function scope
Rashed Rahat
  • 2,357
  • 2
  • 18
  • 38
Malachi
  • 3,205
  • 4
  • 29
  • 46
0

try this

 <!DOCTYPE html>
    <html>
    <head>
    <title>Page Title</title>
    </head>
    <body>

     <script type="text/javascript">
        function password_change_function(){
           var x= document.getElementById("password_change").value;
           alert("Password is changed");
           window.location = "http://example.com/foo.php";
           }

        </script>
    <input id="password_change" type="submit" value="Submit" onclick="password_change_function()"/>
    </body>
    </html>
Dhiarj Sharma
  • 328
  • 3
  • 12
0

You can achieve your goal by swapping the two lines of code:

From this:

alert("Password is changed");
window.location.assign("viewprofile.php");}

To this:

window.location.assign("viewprofile.php");
alert("Password is changed");}
Toby Speight
  • 27,591
  • 48
  • 66
  • 103
Rashed Rahat
  • 2,357
  • 2
  • 18
  • 38