Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Change Focus to next field - Find Element ID??

Status
Not open for further replies.

ardan

Technical User
Apr 22, 2003
27
US
Hi All,

I am trying to change the focus onfocus to another field. The problem is since the formfields are generated on the fly I don't know how many there may be. i.e. when user enters the system generates however many lines the user said they need. It looks like a table, the first field is a "line number" if they focus on the line number field I would like it to move to the next field instead. The problem is they may be on the 2nd, 3rd line etc.....If I knew the element number I could change the focus to the next element.....Any ideas on how I should handle this....????

Thanks,...

End of Line
 
Generate a hidden input element and write the number of fields in it when your script is done generating the lines, read that to take care of your problem.

Lee
 
If I knew the element number I could change the focus to the next element.

Can't you give each element a unique ID, and simply read that?

If that doesn't work, perhaps you could explain a bit clearer about what your document structure is like - I'm having a hard job understanding exactly why you don't do what I've just suggested, or simply walk the DOM tree... so it may be that you need to be a bit clearer in your description.

Dan

[tt]Dan's Page [blue]@[/blue] Code Couch
[/tt]
 
I guess I didn't word it as clearly as i should...

1. On an start screen I ask the user how many lines of data they need to enter...

2. After the user clicks Ok, I use PHP to loop and create as many lines as requested by the user.

3. So if the user select 8 the system will loop 8 times and create 8 lines. The lines look like an excel table, 7 columns, and each form has a unique name based on the line it is on. i.e line 2 column 2 is named t22, line 3 column 4 is named t34.

4. The first column contains the line number, 1,2,3 etc...

What I would like to do is when the user clicks in any of the line number fields for the focus to move from that field to the right one field. I could do this by not putting the field in a form, just display the data but I know there is a way to move the focus to the next form field.

Does anyone have an idea how to do this, SInce there may be many lines I am not sure where the user focus is when they click, in other words which line they are on. So the really question is there a way to know what line the focus is on so I could change the focus to another field....

Hope this clears it some...

Again, Thanks for any ideas....

End of Line
 
Show us the code you have so far to handle this, then we can help from there.

Lee
 
I could not easily pull the code to run by itself so I wrote a little code that will show the problem and what I am wanting to do....

In the below example when the user changes the value in the input field 'test1' I would like to move the focus to 'test4'. I want to do this WITHOUT using the names of the form fields. I was hoping to find the calling form field's element number and move the focus by adding to the element number. If there is another way I would welcome the suggestion....

===== Begin

<script language="Javascript">
function testrun()
{
var avat = **** I would like avat to equal the element
number for the calling form field ****
document.form[0].elements[avat + 3].focus;
}

</script>

<html>
<form name='form1'>
<input name='test1' type='text' onblur='testrun();'>
<input name='test2' type='text'>
<input name='test3' type='text'>
<input name='test4' type='text'>
</form>
</html>


Thanks,,,,

End of Line
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top