JVerstry JVerstry - 1 year ago 78
HTML Question

How to avoid automatic focus on first input field when popping a HTML form as a JQuery dialog?

I have seen similar questions on SO, including this one, which is old. I read and followed links, but it is unclear whether there is a proper solution to this issue today.

My bottom issue is that I am using HTML's

on the input fields. By focusing automatically on the first field, its placeholder is not visible to the user anymore.


Here is my HTML code:

<div id='LOGIN_FORM' title="Login">
<form action="">
<input type="text" name="login_id" required="required"
placeholder="Enter user ID" /><br />
<input type="password" name="login_pwd" required="required"
placeholder="Enter password" /><br />

Here is my JS code:

$("#login").click(function() {
$("#LOGIN_FORM").dialog({ modal: true }, { buttons: [
text: "Ok",
click: function() { $(this).dialog("close"); }
] });

Answer Source

A solution is to set tabindex="-1" on ALL input fields to keep HTML placeholders visible.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download