I have button on my HTML page. Initially i was using
<input name="op" id="changepass_submit" value="Change Password" disabled="disabled" class="form-submit" type="button" onClick="change_passwd();" />.
Using this i am able to call the javascript function change_passwd() which has it’s definition as,
function change_passwd()
{
var o_pass = document.getElementById('o_passwd').value;
var n_pass = document.getElementById('n_passwd').value;
var c_pass = document.getElementById('c_passwd').value;
if(n_pass == "")
alert("New Password can not be empty!");
else
{
if(n_pass == o_pass)
{
alert('New password and old password are same! Please choose different new password.');
}
else
{
o_pass = rtrim(ltrim(o_pass));
n_pass = rtrim(ltrim(n_pass));
$.ajax({
type: "POST",
data: {o_pass:o_pass,n_pass:n_pass},
url: "changepass",
success: function(response) {
var result = eval(response);
alert(result[1]);
window.location = "/my_profile";
}
});
}
}
}
It works fine.
But when i change <input> tag to:
<button name="op" id="changepass_submit" disabled="disabled" class="form-submit" onClick="change_passwd();" style="width:150px;"><strong>Change Password</strong></button>
it gives jQuery error..
why so? If any body has any suggestions or answers pls let me know. Thanks in advance.
I don’t know about the jQuery error (what’s the error?) but a
<button>istype="submit"by default and nottype="button". That means when clicked (assuming it is not disabled as in the markup), since you do notreturn falseto cancel the default action, the form will continue to submit, potentially cancelling yourajax()operation.