Forum Moderators: open

Message Too Old, No Replies

form.reset() is not a function

         

daveginorge

5:04 pm on May 14, 2009 (gmt 0)

10+ Year Member



Hi All

I am trying to simulate using the reset button using Javascripts reset() function but I keep getting the error form.reset is not a function.

<form method="post" action="mail.php" onsubmit="return checkForm(this)" name="webform" id="webform">

I have tried
document.webform.reset();
document.getElementById("webform").reset();

I always get the same error using FF error console.
I have googled extensively and it seems that the code should work. I seem to be missing something.
Please can someone help me a little here.

Thanks in advance

DrDoc

5:47 pm on May 14, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Have you validated your HTML, just to eliminate the chance of there being a DOM issue?

daveginorge

7:28 pm on May 14, 2009 (gmt 0)

10+ Year Member



Yes the page validates with the validator

daveginorge

7:37 pm on May 14, 2009 (gmt 0)

10+ Year Member



OK found the answer in Mozilla's developer center.
If a form control (such as a reset button) has a name or id of reset it will mask the form's reset method.

I had the button I was using to trigger the resetting of the form named "reset".

That's something new learnt for me today.

dreamcatcher

9:56 am on May 15, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Silly question, but is the reset button within the <form> tags?

dc

daveginorge

4:42 pm on May 15, 2009 (gmt 0)

10+ Year Member



Hi DC. No there was not a <input type="reset" name="reset" id="reset" /> but I created a normal button
<input type="button" name="reset" id="reset" /> to trigger my javascript:

function resetForm() {
form.reset();
other code.......;
}

According to Mozilla's dev center any control holding the name or id "reset" will mask the form.reset() function. Changing the name and id of the button to "clear" solved the problem.