skip to Main Content

I’m using a Twitter Bootstrap 3 form with (4) Radio form controls. When a user clicks on any of the four radio controls, an <input type="text"> appears. How do I make it, so that the first input, on any radio option select is “autofocus”.

on radio select input field autofocus

To see code, if you may, please visit: https://von.host/cart.php?a=add&pid=20

It just seems silly to have the user click a radio button, than click again on the input field and type, than click once more on submit button…instead of three clicks, I wish to make it two.

p.s. – i added “autofocus” to all (4) input fields, but it only worked for the first one…of course ^ _ ^

2

Answers


  1. I think, you can this only with a little part of javascript 🙂 for example:

    $('input[type="radio"]').focus(function(){
        $(this).parent().find('input[type="text"]').focus();
    });
    

    In nutshell, this code pass the focus for the input field, when the radio give it.

    Login or Signup to reply.
  2. Keep the autofocus attribute in the first one and use this jQuery code:

    $('.domainoptions .option input:radio[name="domainoption"]').change(
      function(){
        $(this).parent().next().find('input[type="text"]').first().focus();
      }
    );
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search