Announcement

Collapse
No announcement yet.

Event on when Text field content changes

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Event on when Text field content changes

    I looking a long time already for an event which fires when the content of a (text)field changes.

    Example 1:
    I have a USB-barcode-handscanner, the focus is on the barcode field in the form
    When I scan the barcode, the characters in the barcode comes in the field.
    So far so good. But after that there should fire automatic a method to process the content of the barcodefield.
    I have to push TAB now (in combination with an ajax event) but I want to fire in automatic with not having pushing the TAB.

    Example 2:
    I have a text field with the focus. What I want is, that in the moment I type a special karakter an event fires.
    Also here without leaving the textfield.

    Would be nice...

    Regards Bert

  • #2
    Originally posted by ctmservice View Post
    I looking a long time already for an event which fires when the content of a (text)field changes.

    Example 1:
    I have a USB-barcode-handscanner, the focus is on the barcode field in the form
    When I scan the barcode, the characters in the barcode comes in the field.
    So far so good. But after that there should fire automatic a method to process the content of the barcodefield.
    I have to push TAB now (in combination with an ajax event) but I want to fire in automatic with not having pushing the TAB.

    Example 2:
    I have a text field with the focus. What I want is, that in the moment I type a special karakter an event fires.
    Also here without leaving the textfield.

    Would be nice...

    Regards Bert
    There's an onchange ajax event which fires when changing. My site is out of dns currently (!@###!!! provider) but when it comes up you can solve your first issue when you look into our faq pages. The second situation needs to be taken care of by yourself by injecting a javascript procedure. Can't help you with that as Im not a js guuru...
    Albert Drent
    aducom software netherlands
    scriptcase partner, reseller, support and (turn-key) development
    www.scriptcase.eu / www.scriptcase.nl

    Comment


    • #3
      Hi,
      here's something to give you an idea.
      Put it in the JavaScript section of your form.

      Code:
      function special_char(e)
      {
        var char_code;
        if (window.event)
        {
          char_code = window.event.charCode; // IE
        }
        else char_code = e.which; // FF
      
        if (char_code == 64) // in case you don't know the character code: String.fromCharCode(char_code) == '@'
        { 
          alert('Congratulations!! You nailed it!');
          return false;
        }
        else return true;
      }
      
      document.F1.your_field_name.onkeypress=special_char;

      Here is a tool to get character and key codes: http://www.w3.org/2002/09/tests/keys-cancel2.html

      jsb
      Last edited by jsbinca; 08-02-2014, 02:03 PM.

      Comment


      • #4
        Yes jsb
        I think I am very close with your help

        In the form I copied your script in the js in the field: barcode -> onchange

        Then it looks like this:
        ----------------------------------------------------------------------------
        function sc_barcode_onchange()
        {
        function special_char(e)
        {
        var char_code;
        if (window.event)
        {
        char_code = window.event.charCode; // IE
        }
        else char_code = e.which; // FF

        if (char_code == 64) // in case you don't know the character code: String.fromCharCode(char_code) == '@'
        {
        alert('Congratulations!! You nailed it!');
        return false;
        }
        else return true;
        }

        document.F1.barcode.onkeypress=special_char;
        }
        -------------------------------------------------------------------------------------
        I use the "@" with the keyboard before I continue with the barcode scanner etc.
        Can you check and advise me what I did wrong...
        It very important for me....thanks in advance

        Bert Steinebach

        @ Yes Albert I wil have a look at your FAQ when the site is back...
        Wil bovendien een keer met je afspreken...
        Last edited by ctmservice; 08-02-2014, 03:14 PM.

        Comment


        • #5
          It doesn't belong into an AjaxEvent, delete it from there.

          Click on 'JavaScript' in the left pane.
          Chose 'Form' from 'Select the object'.
          Chose 'OnLoad' from 'Select the event'.
          Paste the code into the text area and hit Update.

          That's it.

          jsb

          Comment


          • #6
            Yes, I works....Thank you very much.
            This gives me an opening for what I want.
            Kind Regards Bert

            Comment


            • #7
              I finished this with what I wanted a long time already:

              In a multi-line textfield I can now type an ":" and then the actual date and name of the login user automaticaly comes with a text string like:

              29-12-2014: bert >here you can type your note

              jave code: -> the [usr_namelogin] you have to pick from the loginform

              function special_char(e)
              {
              var char_code;
              if (window.event)
              {
              char_code = window.event.charCode; // IE
              }
              else char_code = e.which;

              if (char_code == 58)
              {
              var content = document.F1.note.value; //it takes the whole content of the field
              var content = content.substring(0, content.length - 1); //to cut off the typed ":"

              var d = new Date();
              var curr_date = d.getDate();
              var curr_month = d.getMonth()+1;
              var curr_year = d.getFullYear();

              var name = <?php echo json_encode($_SESSION['usr_namelogin']); ?>;

              document.F1.reactie.value = (content + curr_date + "-" + curr_month + "-" + curr_year + " : " + name + " >");
              return false;
              }
              else return true;
              }

              document.F1.note.onkeypress=special_char;
              Last edited by ctmservice; 12-29-2014, 11:44 AM.

              Comment

              Working...
              X