Control charcters in form input field

P

Paul Jørstad

Hello!

In a form I have an input field. It's supposed to get input form a
scanning device. Thus, the input might contain special characters (like
the Group Separator in a EAN barcode). Now, I want to manipulate a
little with the input in a javascript, but I'm not able to find the
Group Separator:

input = document.main.input.value;
var a = input.split("");
var i;
for(i=0;i<a.length;i++) {
if(/\x1D/.test(a)) {
alert("GS");
}
}

This is a snip that parses the input, character by character, and gives
me an alert if the Group Separator (Hex: 1D) is found. But it never
matches, even if I know that the input string contains in. I have a
similar script written in Perl, an that script finds the Group Separtor.

What can I do to find the %"#¤ Group Separator??

Thnx in advice!
- Paul Jørstad
 
D

Dr John Stockton

JRS: In article <[email protected]>, seen in
In a form I have an input field. It's supposed to get input form a
scanning device. Thus, the input might contain special characters (like
the Group Separator in a EAN barcode). Now, I want to manipulate a
little with the input in a javascript, but I'm not able to find the
Group Separator:

input = document.main.input.value;
var a = input.split("");
var i;
for(i=0;i<a.length;i++) {
if(/\x1D/.test(a)) {
alert("GS");
}
}

This is a snip that parses the input, character by character, and gives
me an alert if the Group Separator (Hex: 1D) is found. But it never
matches, even if I know that the input string contains in. I have a
similar script written in Perl, an that script finds the Group Separtor.


Substituting the first line, it works for me in MSIE4. Can you be
certain that the GS is really present? Compare the lengths of var input
and of var a with the expected character count.

It also works using the RegExp to test var input directly, without
split.
 
G

Greg

Paul Jørstad said:
Hello!

In a form I have an input field. It's supposed to get input form a
scanning device. Thus, the input might contain special characters (like
the Group Separator in a EAN barcode). Now, I want to manipulate a
little with the input in a javascript, but I'm not able to find the
Group Separator:

input = document.main.input.value;
var a = input.split("");
var i;
for(i=0;i<a.length;i++) {
if(/\x1D/.test(a)) {
alert("GS");
}
}

This is a snip that parses the input, character by character, and gives
me an alert if the Group Separator (Hex: 1D) is found. But it never
matches, even if I know that the input string contains in. I have a
similar script written in Perl, an that script finds the Group Separtor.

What can I do to find the %"#¤ Group Separator??

Thnx in advice!
- Paul Jørstad


I can't help you, but the following displays matches for both x and y
in my quick test in IE6 and Netscape 7:

<script type='text/javascript'>
function f(){
var x = txt1.value;
var y = '\x1D';
var s = '';
if(/\x1D/.test(x)) {
s += "x matches";
}else{
s += "x does not match";
}
s += '\n';
if(/\x1D/.test(y)) {
s += "y matches";
}else{
s += "y does not match";
}
alert(s);
}
window.onload = function(){
window.form1 = window.form1 || document.getElementById('form1');
window.txt1 = window.txt1 || form1.elements['txt1'];
txt1.value = '\x1D';
}
</script>
<form id='form1' name='form1' action='a.htm' method='post'>
<input type='text' name='txt1' id='txt1' value='' />
</form>
<br>
<a href='b.htm' name='a1' id='a1' onclick='f(); return false;'>f()</a>

Not an expert. FWIW.
 
P

Paul Jørstad

Dr said:
Can you be certain that the GS is really present?

In fact I'm not sure.. If I parses the input from the scanner in a
perl-script reading from stdin, I got this:

$ perl input.pl

S > 83
? > 29
2 > 50

First character is "S", which is ASCII value 83. As, you see, the second
character is the GS having ASCII value=29. The exact same input is put
into the form element, but then the GS is gone for some reason. If I do
a split(""), and alerts every character, the GS never pops up. So it
seems that the browser is the problem, ripping of special characters,
ie. the input field can't receive control characters.

- paul
 
A

asdf asdf

Hi,

You might try hooking into one of the browser's onkeyxyz events (up|down|press).

If you have an "onpaste" event available to you, that's another possibility.

I'm just taking wild guesses at how the barcode info is getting into your web page.

good luck!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top