Page 1 of 1

[SOLVED] Automatically selecting field for entry

Posted: Thu Jun 28, 2007 2:18 pm
by ktsugihara
Hey so I have my program totally made. to understand what im asking for, i need to tell you what the program is all about...

so i have a tablet pc and a scan gun. when people walk into my stock room, they have to sign in with their badge. I have it set up so they can just scan their badge nad then i scan mine saying i let them in. so the scan gun is set up to hit "enter" automatically. so i scan his, it goes to the next screen, and then i go to scan my badge, but i have to select the field. i just want it to automatically select the feild. is that possible?

Posted: Thu Jun 28, 2007 2:31 pm
by superdezign
.... Is this using HTML....?

Posted: Thu Jun 28, 2007 2:32 pm
by ktsugihara
erm.. i use the PHP to communicate with a mysql database. but aw crap the forms are in HTML my bad ill go to am HTML forum

[edit]i dont suppose someone could help anyways?[/edit]

Posted: Thu Jun 28, 2007 2:40 pm
by superdezign
Hehe, we do HTML here as well. Kind of hard to avoid in web development. ;)

I think giving the HTML element a tabindex attribute of '1' should do it. If not, you could do a quick JavaScript that calls the element's focus() function onLoad.

Posted: Thu Jun 28, 2007 2:48 pm
by ktsugihara

Code: Select all

<input type="text" name="e_wwid" tabindex="1">
so like that? just ad tabindex=1 to the input?

[edit]

Hmm it deosnt seem to be working... any other ideas?

[/edit]

Posted: Thu Jun 28, 2007 3:45 pm
by feyd
Tabindex sets the order in which fields are iterated over when using the tab key. You're looking for the focus() method in Javascript.

Posted: Thu Jun 28, 2007 3:52 pm
by ktsugihara
sweet thansk!!! ehh.. how do i format it? :-) sorry for being a pain


<script language="JavaScript">
<!--

document.FORM NAME.?? what is this variable??.focus();

//-->
</script>

Posted: Thu Jun 28, 2007 3:54 pm
by feyd
Do some research; try some stuff.

Posted: Thu Jun 28, 2007 3:55 pm
by ktsugihara
alright thanks alot for the help!!!

[edit]
Here is the solution:

Code: Select all

<html>
<title>test</title>
<body>
<script type="text/javascript">
   function formfocus() {
      document.getElementById('tester').focus();
   }
   window.onload = formfocus;
</script>
<form name=testing>
<p>Test</p>
<input type=text name=tester id=tester>
</input>
</form>
</body>
</html>
Note:

Code: Select all

<input type=text name=tester id=tester>
you need the ID tag for the 'getElementById()' to work correctly.