-1

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.

4
  • 1
    This question really doesn't make any sense. Specifically, what does, "change tag to Change Password " mean? Change what tag? Where? Commented Oct 25, 2010 at 14:54
  • 1
    Edited the question formatting so it does make more sense! But post the jQuery error you get too. Commented Oct 25, 2010 at 14:56
  • just forget the disabled attribute of the input and button element because i am changing its value in the middle. Commented Oct 25, 2010 at 14:56
  • @aashish what's the error? Also sorry I didn't guess that it was a Markdown problem. Commented Oct 25, 2010 at 14:58

1 Answer 1

1

I don't know about the jQuery error (what's the error?) but a <button> is type="submit" by default and not type="button". That means when clicked (assuming it is not disabled as in the markup), since you do not return false to cancel the default action, the form will continue to submit, potentially cancelling your ajax() operation.

Sign up to request clarification or add additional context in comments.

5 Comments

He's got type="button" way down on the far end of the opening tag.
i don't have any form in the HTML page. Still it can give this error ?
It worked when i put attribute type="button" in <button> tag. ty bobince. I have one question when we are specifying that the tag is button why to give type="button" ??
@bobince oh now I see - he went from <input> to <button>. Boy I'm pretty slow sometimes.
<button> can replace three types of button: actionless button, a form submit or a reset. So it's necessary to state which you mean. I guess submit was chosen because button on its own does nothing, requiring JavaScript intervention, so submit was seen as the more likely case. (IE didn't agree, defaulting to button instead, so omitting type is unreliable.) Incidentally you don't necessarily need to use a <button> if all you want is bold text; a plain input with CSS font-weight can do that.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.