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!

Copy value from text 1 to other textboxes depending on value 1

Status
Not open for further replies.

cesaru

Technical User
Jan 31, 2008
19
US
Hello,

I have a small asp.net formview with 4 textboxes where the user is using a scanner to scan barcodes.

What I want to do is to have a html Scan Textbox outside the formview control where the user scans the barcode and if the data starts with the letter "T" then copy that value to the
formview$trucktextbox and if the scan starts with "D" then copy the value to the formview$doortextbox and so on.



I'm new in javacript so please bare with me. any help i'll appreciated.

thank you

Thanks!
 
What I want to do is to have a html Scan Textbox outside the formview control

What is an html Scan Textbox? Many of us are well versed in javascript and could offer you help, but I'm willing to bet that many of us (myself included) have never used a barcode scanner to populate data in a webpage. Perhaps you could show the code that you have so far.

-kaht

Lisa, if you don't like your job you don't strike. You just go in every day and do it really half-assed. That's the American way. - Homer Simpson

[small]<P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <.</B>[/small]
 
Sorry I should have said client side html textbox. No server side textbox.

this is what I need to do
type or scaned to a text box ( no server side) then when press ENTER key check for first letter if starts with "T" then
copy that value to a server side textbox.

Hope i'm clearer this time. thanks!

CZ
 
kaht said:
but I'm willing to bet that many of us (myself included) have never used a barcode scanner to populate data in a webpage.
I did one a while back for a school's laptop service centre... all the school's laptops were barcoded, scan the code and the service history of the lappy came up on screen... rather a nice solution if I do say so myself... digression

cesaru, if I understand your problem correctly you're using one textbox on the page as a sort of staging-area for the value read in by the scanner so that you can decide what to do with it once it's read in.

So the simple outline is:
Read barcode value into staging field with scanner
press enter
determine the first letter of the barcode value
store the barcode value in the matching field

We can do this by writing an onkeypress handler for the staging field:
Code:
function storeValue(intKeyCode, objStagingField){
	if(intKeyCode == 13){ //13 is the keycode for 'enter'
	    //Read the value out of the staging field
		var strReadValue = objStagingField.value;
		
		//Grab the first character from the read value
		var strFirstChar = strReadValue.slice(0,1).toUpperCase();
		
		//Assign the target textbox based on the first character
		switch(strFirstChar){
			case "D" : {
				document.getElementById("textbox1ID").value = strReadValue;
				break;
			}
			case "T" : {
				document.getElementById("textbox2ID").value = strReadValue;
				break;
			}
			case "U" : {
				document.getElementById("textbox3ID").value = strReadValue;
				break;
			}
			case "V" : {
				document.getElementById("textbox4ID").value = strReadValue;
				break;
			}
			default :{
				//If we don't match one of those conditions
				//show an error message
				alert(strReadValue + " does not appear to be a valid value.")
			}
		}
		//OK value stored or error message delivered, tidy up time
		
		//Clear out the value from the staging textbox
		objStagingField.value = "";
		
		//Put the cursor back there for the next read
		objStagingField.focus();
	}
}

Which you would call as:
Code:
<input type="text" id="stagingfield" name="stagingfield" onkeypress="storeValue(event.keyCode, this)"/>

And of course change the letters and text field id values to suit your page.

[sub]Never be afraid to share your dreams with the world.
There's nothing the world loves more than the taste of really sweet dreams.
[/sub]

Webflo
 
dwarfthrower, thank you very, very much!
you rock man! this was awesome.... the only think is that i hope it works on the IE on the handheld. This will make life easier.

Muchas Gracias!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top