-2

Here is the HTML5 Code:

<form name="memberInfo">
<table border=1>
<tr><td>Username</td><td><input id="username"   /></td></tr>
<button type = "reset" id = "resetButton">Reset</button>
<input type=button value="submit" onclick="Validate()"/>
</table>
</form>

and here is the JavaScript code:

window.onload =function(){
var _getForm = document.getElementById("memberInfo");
_getForm.addEventListener('reset',function(){
document.getElementById("username").focus()
})
}

2 Answers2

0
<form id = "myForm">
<input type = "text" id ="text1">
<input type = "text" id ="text2">
<input type = "text" id ="text3">
<button type = "reset" id = "restButton">Reset</button>
</form> 

JS

$("#myForm").submit(function()
{
$('#myForm').trigger("reset");
$('#text1').focus();
return true;
});
Vinoth Narayan
  • 275
  • 2
  • 15
-1

Use button type ="reset" and focus()

Hope this snippet will be useful

HTML

<form id = "myForm">
    <input type = "text" id ="text1">
    <input type = "text" id ="text2">
    <input type = "text" id ="text3">
    <button type = "reset" id = "restButton">Reset</button>
    </form>

JS

   var _getForm = document.getElementById("myForm");
    _getForm.addEventListener('reset',function(){
    document.getElementById("text1").focus()
    })

Check this jsfiddle

EDIT

You can use firstElementChild instead of using document.getElementById("firtChild").

Updated jsFiddle

Edit-2

If you have put your code inside head tag, you can use window.onload to attach eventlistener after window has loaded

 window.onload =function(){
    var _getForm = document.getElementById("your form id");
    _getForm.addEventListener('reset',function(){
    document.getElementById("text1").focus()
    })
    }

EDIT-3

With latest changes in original questions here are few updates

Note

  1. There is no form with id=memberInfovar. There is form with name="memberInfovar".So this _getForm = document.getElementById("memberInfo"); will throwaddEventListener of null
  2. <input id="username" /> add type of this input, that is input type = "text"
  3. <input type=button. The type must be wrapped inside double quotes, that is <input type="button">

Check this jsfiddle

brk
  • 48,835
  • 10
  • 56
  • 78