Solved

Scanned Barcode to Visual Basic Textboxes - Change Textbox Focus with Javascript

Posted on 2014-03-18
9
1,258 Views
Last Modified: 2016-10-28
Hi all!

We have a .NET application to register items in a large archive. The location in the archive is a combination of room, section, and shelf. Presently the item number and location is entered manually in the archive system but we want to switch to barcodes - a location will have a barcode and an item in the archive will have as barcode.

On a webform we have two textboxes and a button and want to perform this:

1/ Focus is set on the first textbox.
2/ The items barcode is scanned and the scanned value goes in the first textbox.
3/ At the same time as 2/ happens Javascript must move focus to the second textbox.
4/ The location barcode is scanned and the scanned value goes in the second textbox.
5/ At the same time as 4/ happens Javascript must move focus to the textbox in order for nthe user to press enter and have the form processed. Instead of the user press enter, is it possible to have Javascript 'click the button'?

I have tried this:

TextBox1.Attributes.Add("onkeydown", "document.getElementById('" & TextBox1.ClientID & "').value=''; document.getElementById('" & TextBox2.ClientID & "').focus();")

but when I scan in TextBox1, focus is moved to TextBox2 and the scanned value is transferred to TextBox2 but should be transferred to TextBox1 before focus is changed.

Any suggestions?
0
Comment
Question by:Kim Neesgaard
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 2
9 Comments
 
LVL 83

Expert Comment

by:CodeCruiser
ID: 39940091
Try using "onchange" event instead of "onkeypress". If you get the same behaviour, you may have to add a condition like number of characters in the textbox to change the focus because the focus is changing as soon as first character enters the textbox.
0
 

Author Comment

by:Kim Neesgaard
ID: 39941669
-> CodeCruiser
In this case I cannot use number of characters as it is a location with different number of characters.

If I use:

TextBox1.Attributes.Add("onchange", "document.getElementById('" & TextBox2.ClientID & "').focus();")

the scanned value is entered in TextBox1 but focus is not set on TextBox2?
0
 
LVL 83

Accepted Solution

by:
CodeCruiser earned 300 total points
ID: 39948891
Does your scanner provide any settings? Such as sending a Tab key at the end of the scan?
0
Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

 

Author Comment

by:Kim Neesgaard
ID: 39952887
I have now adjusted the scanner to add a at the end of the scan and will try to detect it.
0
 

Author Comment

by:Kim Neesgaard
ID: 39952890
...to add a tab at the end...
0
 

Author Comment

by:Kim Neesgaard
ID: 39955703
-> CodeCruiser
Tab was the right cue!!

I contacted my scanner provider and learned how to add a tab-character AFTER the scanned value and this works. When a value is scanned to a textbox, the tab moves the cursor to the next tab order on the form. A simple and good solution!

Thank you very much!!
Barcode-Scanner.png
0
 

Expert Comment

by:RAM PRASAD
ID: 41863707
I have used two textboxes as text1 and text2 and one comm1 conttrol .. now we use these  code . after running the program auto cursor will show in text1. now i go to scan then scaned value all inputed in the text1. and cursor auto move to text2 but next scanning not show..???? now i will want to scan second barcode in  text2 for matching two barcode are related one system or not...
i used coding in mscomm-oncomm()

' for connection making on form load()
MSComm1.CommPort=1
MSComm1.CommPort=3
MSComm1.Setting="9600,n,8,1"
MSComm1.InputLen=0
MSComm1.InbufferSize=100
MSComm1.Rthershold=0
MSComm1.PortOpen=true
MSComm1.Output="ok"
MSComm1.OutBufferCount
........................
Now On MSComm1..()
Dim i As Integer
Dim buffer As String
buffer=""
buffer=MSComm1.Input
for i=1to Len(buffer)
text1.text=text1.text &Chr(Asc(Mid$(buffer,i,17)))
next j
buffer=""
buffer=MSComm1.Input
for j=1to Len(buffer)
text2.text=text2.text &Chr(Asc(Mid$(buffer,j,17)))
next j
.....ok please Solve this ?
0
 

Author Comment

by:Kim Neesgaard
ID: 41863780
Hi RAM PRASAD!

As you can see above, we used the solution to have tab added to the barcode reading.


Best regards
Kim Neesgaard
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
disadvantage of code behind appoarch in asp.net 3 29
Record locking on classic ASP 3 40
Put POST values into cookies. 14 34
Connect Gridview column to Textbox in C# 2 41
Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.

726 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question