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

javascript - button type reset not working for default values - Stack Overflow

programmeradmin1浏览0评论

Hi This is my form...

<form id="frmer" class="form-inline" method="POST">
    <input name="inp1" value="sda"/>
    <button type="submit" class="btn btn-primary mr5">Search</button>
    <button type="reset" class="btn btn-default" form="frmer">Reset</button>
</form>

I want to clear this default value also from text input when I click the reset button. But unfortunately it wouldn't happen. If someone know how to archive it or any workaround it would be a great help..

Hi This is my form...

<form id="frmer" class="form-inline" method="POST">
    <input name="inp1" value="sda"/>
    <button type="submit" class="btn btn-primary mr5">Search</button>
    <button type="reset" class="btn btn-default" form="frmer">Reset</button>
</form>

I want to clear this default value also from text input when I click the reset button. But unfortunately it wouldn't happen. If someone know how to archive it or any workaround it would be a great help..

Share asked Nov 24, 2016 at 13:40 vimuthvimuth 5,68249 gold badges93 silver badges125 bronze badges 5
  • 3 @LuudJacobs — Why? – Quentin Commented Nov 24, 2016 at 13:43
  • Depending on your usecase, I'd remend using placeholder instead of a default value. To clear the fields, you will need to use js – Tom M Commented Nov 24, 2016 at 13:44
  • 1 Placeholder … or <label>, since the field doesn't have a <label> at the moment, that is probably the real solution. – Quentin Commented Nov 24, 2016 at 13:45
  • We cannot reset the value in HTML for reset button.. You must have to use jquery or javascript yo reset the form. – Sachin Sanchaniya Commented Nov 24, 2016 at 13:47
  • @quentin, nevermind... brainfart – Luuuud Commented Nov 24, 2016 at 13:55
Add a ment  | 

1 Answer 1

Reset to default 8

Reset means "reset" not "blank". It is supposed to restore the default values.

If you want to blank the form, then you'll need JavaScript.

Loop over each control and test what type it is. Ignore buttons. Set the values of text, search, number, etc fields to "" (an empty string). Set the checked property of checkboxes to false and so on.

发布评论

评论列表(0)

  1. 暂无评论