By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
449,423 Members | 1,294 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 449,423 IT Pros & Developers. It's quick & easy.

Control charcters in form input field

P: n/a
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[i])) {
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

Jul 20 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a
Paul Jørstad <pa***@onlineREMOVE.no> wrote in message news:<Tc*******************@news4.e.nsc.no>...
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[i])) {
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.
Jul 20 '05 #2

P: n/a
JRS: In article <Tc*******************@news4.e.nsc.no>, seen in
news:comp.lang.javascript, Paul Jørstad <pa***@onlineREMOVE.no> posted
at Wed, 17 Sep 2003 15:20:50 :-
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[i])) {
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.

--
© John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v4.00 IE 4 ©
<URL:http://jibbering.com/faq/> Jim Ley's FAQ for news:comp.lang.javascript
<URL:http://www.merlyn.demon.co.uk/js-index.htm> JS maths, dates, sources.
<URL:http://www.merlyn.demon.co.uk/> TP/BP/Delphi/JS/&c., FAQ topics, links.
Jul 20 '05 #3

P: n/a

Dr John Stockton wrote:
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

Jul 20 '05 #4

P: n/a
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!
Jul 20 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.