First name:

Warn when tabbing by age

I received several forms. I have 5 text fields.

<form action="action_page.php">
  First name:<br>
  <input type="text" name="firstname"br>
  Last name:<br>
  <input type="text" name="lastname""><br>
  Age:<br>
  <input type="text" name="age"br>
  State:<br>
  <input type="text" name="state"br>
  Profession:<br>
  <input type="text" name="profession"br><br>
  <input type="submit" value="Submit">
</form>

While the user is moving through the fields, how to set up an alert when focused on the field age?

+4
source share
5 answers

While the user is moving through the fields, how can I set a warning when focused on the age field?

Other answers do not answer this question. The OP wants to show a warning only when tabbing across fields and when focusing a field age.

$(':text').eq($(':text[name="age"]').index('form :text')).on('keyup', function (e) {
    if (e.keyCode === 9) {
        setTimeout(function () {
            alert('Focused');
        });
    }
});

$(':text').eq($(':text[name="age"]').index('form :text')).on('keyup', function (e) {
    if (e.keyCode === 9) {
        setTimeout(function () {
            alert('Focused');
        });
    }
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<form action="action_page.php">
    First name:
    <br>
    <input type="text" name="firstname" br> Last name:
    <br>
    <input type="text" name="lastname">
    <br> Age:
    <br>
    <input type="text" name="age" br> State:
    <br>
    <input type="text" name="state" br> Profession:
    <br>
    <input type="text" name="profession" br>
    <br>
    <input type="submit" value="Submit">
</form>
Run code
+2
source

You can use the focus event:

$("input[name = 'age']").focus(function() {
  alert( "focused on age inputbox." );
});
+4
source
$(document).on('focus',"input[name = 'age']",function(){

alert('Entered age field ');

})

https://jsfiddle.net/5ud8zm06/1/

+2
source

Hi, kindly check https://jsfiddle.net/snvurmez/ you need to use the focus () function

JQuery

$(document).ready(function(){
    $("input[name='age']").on('focus', function(){
    alert('focus on age tab');
  });
});
+1
source

Use the attribute selector to select an input by its name.

Then bind the focus-based event:

$('[name=age]'.on('focus', function() {
     alert('Age is clicked');
});
+1
source

All Articles