Autotab between fields

  • Joffm
  • Joffm's Avatar Topic Author
  • Away
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
4 months 6 days ago #165342 by Joffm
Joffm created the topic: Autotab between fields
Hi, all,
LS Version 2.72.4+171110

I would like to be able to autotab to the next field if the entry exceeds a certain length.
I have a lot of numerical entries which all are only one digit


In Stackoverflow I found the following:
And to be honest, I am not at all familiar with JavaScript.
<script type="text/javascript" charset="utf-8">
  $(document).ready(function(){
    $('input[type="text"]').keyup(function () {
      $this=$(this);
      if ($this.val().length >=1) {
        $this.next('input[type="text"]').focus();
      }
    });
  });
</script>

The length of the entry is recognized, but it does not proceed.

Any help is highly appreciated.

Joffm


Volunteers are not paid.
Not because they are worthless, but because they are priceless
Attachments:

Please Log in or Create an account to join the conversation.

More
4 months 6 days ago #165345 by tpartner
tpartner replied the topic: Autotab between fields
The problem is that .next() will only find direct siblings, whereas you are looking for a text input in the next sibling of the parent '.answer-item' element.

Try this:

<script type="text/javascript" charset="utf-8">
	$(document).ready(function(){
		$('#question{QID} input[type="text"]').keyup(function () {
			if ($(this).val().length >= 1) {
				$(this).closest('.answer-item').next('.answer-item').find('input[type="text"]').focus();
			}
		});
	});
</script>

Cheers,
Tony Partner
Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
The following user(s) said Thank You: Joffm

Please Log in or Create an account to join the conversation.

  • Joffm
  • Joffm's Avatar Topic Author
  • Away
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
4 months 6 days ago #165346 by Joffm
Joffm replied the topic: Autotab between fields
Hi, Tony,
great - as usual.

I promise, one day I will learn about parents and siblings and so on.

Joffm


Volunteers are not paid.
Not because they are worthless, but because they are priceless

Please Log in or Create an account to join the conversation.

Start now!

Just create your account and start using Limesurvey today.

Register now
Join our Newsletter!