0

I am trying to clear my form when the submit button is clicked. It opens a page in a new window, and the value typed in the input field is still showing.

function clearform (formid){
$('#'+formid).reset()
}

And the HTML:

<form id="email-subscribe" action="http://feedburner.google.com/fb/a/mailverify?uri=MYURI&amp;loc=en_US" method="post" target="_blank">
        <input id="email" name="email" type="text" tabindex="1" placeholder="Enter your email" />
        <button type="submit" onClick="clearform('email-subscribe');" >Submit</button>
        </form>

What am I missing?

MultiDev
  • 10,389
  • 24
  • 81
  • 148
  • @j08691 I don't think it's a duplicate of that. See the comments to my answer -- he wants to clear the form and submit it at the same time, which is more complicated. – Barmar Aug 08 '14 at 03:40
  • @Barmar That comment from the OP was added after I closed the question and not part of the original text. If he seeks a delay, why not just use setTimeout and then invoke the reset? – j08691 Aug 08 '14 at 03:42

1 Answers1

2

reset() is a method on the DOM element, not a jQuery method.

document.getElementById(formid).reset();

or

$('#formid')[0].reset();
Barmar
  • 741,623
  • 53
  • 500
  • 612
  • Also, your event fire before the submit. – GramThanos Aug 08 '14 at 03:36
  • Thank you, that cleared the form field, but unfortunately it clears before the POST is made... I changed to `onsubmit`, but that does the same thing. – MultiDev Aug 08 '14 at 03:36
  • Other than using AJAX, I don't think there's a way to run your added code after the post. – Barmar Aug 08 '14 at 03:38
  • `onsubmit` has to be in the `form` element, not the `button`. But then it will still run before the actual submission. – Barmar Aug 08 '14 at 03:39