[SOLVED] Automatically selecting field for entry

JavaScript and client side scripting.

Moderator: General Moderators

Post Reply
ktsugihara
Forum Newbie
Posts: 5
Joined: Thu Jun 28, 2007 2:16 pm

[SOLVED] Automatically selecting field for entry

Post 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?
Last edited by ktsugihara on Thu Jun 28, 2007 5:08 pm, edited 1 time in total.
User avatar
superdezign
DevNet Master
Posts: 4135
Joined: Sat Jan 20, 2007 11:06 pm

Post by superdezign »

.... Is this using HTML....?
ktsugihara
Forum Newbie
Posts: 5
Joined: Thu Jun 28, 2007 2:16 pm

Post 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]
User avatar
superdezign
DevNet Master
Posts: 4135
Joined: Sat Jan 20, 2007 11:06 pm

Post 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.
ktsugihara
Forum Newbie
Posts: 5
Joined: Thu Jun 28, 2007 2:16 pm

Post 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]
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post 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.
ktsugihara
Forum Newbie
Posts: 5
Joined: Thu Jun 28, 2007 2:16 pm

Post 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>
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

Do some research; try some stuff.
ktsugihara
Forum Newbie
Posts: 5
Joined: Thu Jun 28, 2007 2:16 pm

Post 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.
Post Reply