最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

php - how to reset a form after submit? - Stack Overflow

programmeradmin4浏览0评论

I have a simple form, lets say it takes an email address. Once the form is submitted a message stack notifies the user that their address has been submitted successfully. The issue is that after submitting the address the form field with the email still contains the email address that the user typed in, how would I reset this field? Would I have to use JavaScript for this?

Thank you

I have a simple form, lets say it takes an email address. Once the form is submitted a message stack notifies the user that their address has been submitted successfully. The issue is that after submitting the address the form field with the email still contains the email address that the user typed in, how would I reset this field? Would I have to use JavaScript for this?

Thank you

Share Improve this question asked Aug 4, 2009 at 23:53 chicanechicane 2,0813 gold badges20 silver badges15 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 5
window.onload = function () {
    for(var f in document.getElementsByTagName("form"))
        f.reset();
}

This would certainly work, assuming you don't have another onload event already set. If you do, just add the inner bit (lines 2 and 3) to it. And of course this is standard JavaScript, it'll work no matter the framework.

$(':input','#myform')
 .not(':button, :submit, :reset, :hidden')
 .val('')
 .removeAttr('checked')
 .removeAttr('selected');

from this question:
Resetting a multi-stage form with jQuery

Requires jQuery: http://jquery.

发布评论

评论列表(0)

  1. 暂无评论