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

javascript - how to hide required pop-up of input in html - Stack Overflow

programmeradmin0浏览0评论

hide pop-up of required of input using javascript jsfiddle

try to submit with empty input and see the pop-up, so i don't need to display that pop-up and i want the required to validate.

any help i don't need to display any warning.

<form>
  <input type="text" name="name" required="required" value="" />
  <input type="submit" name="submit" value="Submit" />

hide pop-up of required of input using javascript jsfiddle

try to submit with empty input and see the pop-up, so i don't need to display that pop-up and i want the required to validate.

any help i don't need to display any warning.

<form>
  <input type="text" name="name" required="required" value="" />
  <input type="submit" name="submit" value="Submit" />

Share Improve this question asked Sep 4, 2015 at 15:17 kadibrakadibra 991 gold badge1 silver badge9 bronze badges 4
  • So to understand this correctly, you want to validate the form, but don't want the notification? – Johan Commented Sep 4, 2015 at 15:41
  • yes i need the validation but not display notification. – kadibra Commented Sep 4, 2015 at 15:45
  • See my comment on Rafa's answer. – Johan Commented Sep 4, 2015 at 15:48
  • yes @Johan i need validation to work but not displaying notification. – kadibra Commented Sep 4, 2015 at 15:50
Add a comment  | 

2 Answers 2

Reset to default 11

Since this is a HTML5 Event you can prevent the event from triggering the popup and still provide validation (https://developer.mozilla.org/en-US/docs/Web/Events/invalid). A simple event listener will do the job.

To handle focus include an id to that field like so ...

HTML

<input type="text" id="name" name="name" required="required" value="" />

And handle that focus within the return function ...

JS

document.addEventListener('invalid', (function () {
  return function (e) {
    e.preventDefault();
    document.getElementById("name").focus();
  };
})(), true);

EDIT Check it out http://jsfiddle.net/rz6np/9/

autocomplete="off" 

or

autocomplete="nope"

If autocomplete still works on an <input> despite having autocomplete="off", but you can change off to a random string, like nope.

It appears that Chrome now ignores autocomplete="off" unless it is on the <form>-tag.

发布评论

评论列表(0)

  1. 暂无评论