Improve company productivity with a Business Account.Sign Up

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 2185
  • Last Modified:

JSF - Auto Tab To Next Field

Hello:

How can I implement jumping to next field after user enters all the required number of characters?
The document.getElementById('FieldId') ALWAYS returns null!!.

I have code like this

<h:inputtext id "FieldText"  maxlenght = "5" ....... onkeyup ="AutoTabToNextField(this, 'NextField')" />
h:inputtext id = "NextField" ,,,, />

My javascript looks like:

AutoTabToNextField(F1, F2)
 {
  // This is the problem. No Matter what method I use to pass reference to F2,
 //  F2 is ALWAYS ALWAYS NULL or is not an OBJECT!!!

// F1 is passed correctly ... ALWAYS .. I think it is because of using "this"

  if (F1.value.length == F1.maxLength)
  {
    F2.focus();
  }
 }

Thanks,

<<< Ali >>>
0
MohammadAliQureshi
Asked:
MohammadAliQureshi
  • 2
  • 2
2 Solutions
 
Farzad AkbarnejadDeveloperCommented:
Hi,
Instead of 'NextField' pass '[Form Name].NextField' (replace [Form Name] with name of form contains input control.

-FA
0
 
MohammadAliQureshiAuthor Commented:
Hello FarzadA:

I think I have tried that as well and it did not work. However, let me try one more time. I will update you with the results.

Thanks,

<<< Ali >>>
0
 
MohammadAliQureshiAuthor Commented:
Hello:

I found the solution. I had to call my JS function with refernce to nextField as 'formID:FieldID'. Yes it is colon. The way I figured it out was to look at the HTML source created by the JSP and look at what are the ids for different fields. Then, within the function, I get the reference to the field by using document.getElementById to set the focus.

Since FarzadA started my thinking process which led me to a solution, I will award him full points. Thanks for your help FarzadA.

thanks,

<<< Ali >>>
0
 
Farzad AkbarnejadDeveloperCommented:
'formID:FieldID' is JSF naming. You can use forceId=true attribute in inputText tag to force JSF use you id.

<h:inputtext id="NextField" forceId="true" ....

Now you can use its id without pointing to 'formID:'

-FA
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now