Control charcters in form input field

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Paul Jørstad

    Control charcters in form input field

    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.i nput.value;
    var a = input.split("") ;
    var i;
    for(i=0;i<a.len gth;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

  • Greg

    #2
    Re: Control charcters in form input field

    Paul Jørstad <paulj@onlineRE MOVE.no> wrote in message news:<TcZ9b.306 91$Hb.469464@ne ws4.e.nsc.no>.. .[color=blue]
    > 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.i nput.value;
    > var a = input.split("") ;
    > var i;
    > for(i=0;i<a.len gth;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[/color]

    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.getEle mentById('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.

    Comment

    • Dr John Stockton

      #3
      Re: Control charcters in form input field

      JRS: In article <TcZ9b.30691$Hb .469464@news4.e .nsc.no>, seen in
      news:comp.lang. javascript, Paul Jørstad <paulj@onlineRE MOVE.no> posted
      at Wed, 17 Sep 2003 15:20:50 :-
      [color=blue]
      >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.i nput.value;
      > var a = input.split("") ;
      > var i;
      > for(i=0;i<a.len gth;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.[/color]

      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.demo n.co.uk/js-index.htm> JS maths, dates, sources.
      <URL:http://www.merlyn.demo n.co.uk/> TP/BP/Delphi/JS/&c., FAQ topics, links.

      Comment

      • Paul Jørstad

        #4
        Re: Control charcters in form input field


        Dr John Stockton wrote:
        [color=blue]
        > Can you be certain that the GS is really present?[/color]

        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

        Comment

        • asdf asdf

          #5
          Re: Control charcters in form input field

          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!

          Comment

          Working...