Go Back   CodingForums.com > :: Client side development > JavaScript programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 05-02-2012, 03:45 AM   PM User | #1
newphpcoder
Regular Coder

 
Join Date: Aug 2010
Posts: 653
Thanks: 155
Thanked 0 Times in 0 Posts
newphpcoder is an unknown quantity at this point
Using barcode input data to textbox and move to second textbox the focus

Hi..

I have form and i want to input data using barcode and it will display on textbox and after input on the first textbox the focus will go to next textbox untill it will go on the last textbox and on the last textbox it will automatically save the data's on the database.

How is it possible?

here is my sample code:

Code:
<?php
    error_reporting(0);
   date_default_timezone_set("Asia/Singapore"); //set the time zone  
$con = mysql_connect('localhost', 'root','');

if (!$con) {
    echo 'failed';
    die();
}
mysql_select_db("mes", $con);
?>

<html>
<head>
<script type="text/javascript">
function ini()
{

// Retrieve the code
var code =document.getElementById ("code_read_box1").value;
var code =document.getElementById ("code_read_box2").value;
var code =document.getElementById ("code_read_box3").value;
var code =document.getElementById ("code_read_box4").value;
var code =document.getElementById ("code_read_box5").value;
var code =document.getElementById ("code_read_box6").value;
// Return false to prevent the form to submit
return false;

}

</script>
</head>
<body onLoad="document.barcode.code_read_box1.focus()">

<form name=barcode onsubmit = "return ini()">

<input type="text" id="code_read_box1" value="" /><br/>
<input type="text" id="code_read_box2" value="" /><br/>
<input type="text" id="code_read_box3" value="" /><br/>
<input type="text" id="code_read_box4" value="" /><br/>
<input type="text" id="code_read_box5" value="" /><br/>
<input type="text" id="code_read_box6" value="" /><br/>
</form>

</body>
</html>
newphpcoder is offline   Reply With Quote
Old 05-02-2012, 07:59 AM   PM User | #2
Philip M
Supreme Master coder!

 
Philip M's Avatar
 
Join Date: Jun 2002
Location: London, England
Posts: 17,036
Thanks: 197
Thanked 2,411 Times in 2,389 Posts
Philip M has a spectacular aura aboutPhilip M has a spectacular aura aboutPhilip M has a spectacular aura about
It makes no sense to assign the same variable name code to several different HTML elements.

Use onblur() on your final textbox to call some function and submit the form.

All advice is supplied packaged by intellectual weight, and not by volume. Contents may settle slightly in transit.
__________________

All the code given in this post has been tested and is intended to address the question asked.
Unless stated otherwise it is not just a demonstration.
Philip M is offline   Reply With Quote
Old 05-02-2012, 08:04 AM   PM User | #3
newphpcoder
Regular Coder

 
Join Date: Aug 2010
Posts: 653
Thanks: 155
Thanked 0 Times in 0 Posts
newphpcoder is an unknown quantity at this point
Quote:
Originally Posted by Philip M View Post
It makes no sense to assign the same variable name code to several different HTML elements.

Use onblur() on your final textbox to call some function and submit the form.

All advice is supplied packaged by intellectual weight, and not by volume. Contents may settle slightly in transit.
I tried this:

Code:
<?php
    error_reporting(0);
   date_default_timezone_set("Asia/Singapore"); //set the time zone  
$con = mysql_connect('localhost', 'root','');

if (!$con) {
    echo 'failed';
    die();
}
mysql_select_db("mes", $con);
?>

<html>
<head>
<script type="text/javascript">
function ini()
{

// Retrieve the code
/*var code =document.getElementById ("code_read_box1").value;
var code =document.getElementById ("code_read_box2").value;
var code =document.getElementById ("code_read_box3").value;
var code =document.getElementById ("code_read_box4").value;
var code =document.getElementById ("code_read_box5").value;
var code =document.getElementById ("code_read_box6").value;
// Return false to prevent the form to submit
return false;*/

                if (!document.getElementById('code_read_box1').disabled){
                    document.getElementById('code_read_box1').disabled = true;
                }
                if (!document.getElementById('code_read_box2').disabled) {
                    document.getElementById('code_read_box2').disabled = true;
                }
                if (!document.getElementById('code_read_box3').disabled) {
                    document.getElementById('code_read_box3').disabled = true;
                }
                if (!document.getElementById('code_read_box4').disabled) {
                    document.getElementById('code_read_box4').disabled = true;
                }
                if (!document.getElementById('code_read_box5').disabled) {
                    document.getElementById('code_read_box5').disabled = true;
                }
                if (!document.getElementById('code_read_box6').disabled) {
                    document.getElementById('code_read_box6').disabled = true;
                }
}

</script>
</head>
<body onLoad="document.barcode.code_read_box1.focus()">

<form name=barcode onblur = "return ini()">

<input type="text" id="code_read_box1" value="" onblur="this.focus();" onkeypress="return false"/><br/>
<input type="text" id="code_read_box2" value="" onblur="this.focus();" onkeypress="return false"/><br/>
<input type="text" id="code_read_box3" value="" onblur="this.focus();" onkeypress="return false"/><br/>
<input type="text" id="code_read_box4" value="" onblur="this.focus();" onkeypress="return false"/><br/>
<input type="text" id="code_read_box5" value="" onblur="this.focus();" onkeypress="return false"/><br/>
<input type="text" id="code_read_box6" value="" onblur="this.focus();" onkeypress="return false"/><br/>
</form>

</body>
</html>
Yet after I have data on the first textbox, it did not move the focus on the next textbox

Thank you
newphpcoder is offline   Reply With Quote
Old 05-02-2012, 08:12 AM   PM User | #4
Philip M
Supreme Master coder!

 
Philip M's Avatar
 
Join Date: Jun 2002
Location: London, England
Posts: 17,036
Thanks: 197
Thanked 2,411 Times in 2,389 Posts
Philip M has a spectacular aura aboutPhilip M has a spectacular aura aboutPhilip M has a spectacular aura about
onblur="this.focus();"

What do you expect?
__________________

All the code given in this post has been tested and is intended to address the question asked.
Unless stated otherwise it is not just a demonstration.
Philip M is offline   Reply With Quote
Old 05-02-2012, 08:15 AM   PM User | #5
newphpcoder
Regular Coder

 
Join Date: Aug 2010
Posts: 653
Thanks: 155
Thanked 0 Times in 0 Posts
newphpcoder is an unknown quantity at this point
Quote:
Originally Posted by Philip M View Post
onblur="this.focus();"

What do you expect?
It will focus on that textbox if the above textbox has data

I'm sorry.. .I really don't know what the correct syntax

Thank you
newphpcoder is offline   Reply With Quote
Old 01-29-2013, 02:17 AM   PM User | #6
codebarcode
New to the CF scene

 
Join Date: Jan 2013
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
codebarcode is an unknown quantity at this point
Quote:
Originally Posted by newphpcoder View Post
Hi..

I have form and i want to input data using barcode and it will display on textbox and after input on the first textbox the focus will go to next textbox untill it will go on the last textbox and on the last textbox it will automatically save the data's on the database.

How is it possible?

here is my sample code:

Code:
<?php
    error_reporting(0);
   date_default_timezone_set("Asia/Singapore"); //set the time zone  
$con = mysql_connect('localhost', 'root','');

if (!$con) {
    echo 'failed';
    die();
}
mysql_select_db("mes", $con);
?>

<html>
<head>
<script type="text/javascript">
function ini()
{

// Retrieve the code
var code =document.getElementById ("code_read_box1").value;
var code =document.getElementById ("code_read_box2").value;
var code =document.getElementById ("code_read_box3").value;
var code =document.getElementById ("code_read_box4").value;
var code =document.getElementById ("code_read_box5").value;
var code =document.getElementById ("code_read_box6").value;
// Return false to prevent the form to submit
return false;

}

</script>
</head>
<body onLoad="document.barcode.code_read_box1.focus()">

<form name=barcode onsubmit = "return ini()">

<input type="text" id="code_read_box1" value="" /><br/>
<input type="text" id="code_read_box2" value="" /><br/>
<input type="text" id="code_read_box3" value="" /><br/>
<input type="text" id="code_read_box4" value="" /><br/>
<input type="text" id="code_read_box5" value="" /><br/>
<input type="text" id="code_read_box6" value="" /><br/>
</form>

</body>
</html>
Actually I tried the winforms bar code project before in VS to encode barcode in the textbox, after I click the button, it will generate the target data to a barcode like QR Code or something, what you need to add is the click event.
codebarcode is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 06:29 AM.


Advertisement
Log in to turn off these ads.