Jump to content

fill in field after responseText


mrdav30

Recommended Posts

i was wondering if there was a way to fire a function after a field is filled in from xmlHttp.responseText?

 

<html>
<head>
    <title>helloscan</title>
          <!--refreshes page in seconds-->
          <meta http-equiv="refresh" content="18"/>
          <!--produces barcode number and make var-->        
          <meta http-equiv="scanner" content="javascript:doScan('%s')"/>
          <!--following enables scanner-->
          <meta http-equiv="scanner" content="start"/>
          <META HTTP-Equiv="scanner" Content="enabled" />
          <!--adds enter to end of barcode allowing keyevent to occur-->
          <META HTTP-Equiv="scanner" Content="autoenter:enabled" />
          <META HTTP-Equiv="keycapture" content="acceleratekey:all" />
          <META HTTP-Equiv="keycapture" content="keyvalue:0x0D; keyevent:'javascript:get_plunum()'" /> 
          <!--puts quitbutton near top right, for development-->       
          <meta http-equiv="quitbutton" content="visibility: visible;"/>       
    <script language="javascript" type="text/javascript">
    //produces variable for ae_xrefnum
      function doScan(data){
          var divEl = ("%s");
      }
      //on refresh, allows scanner to come back up
      function enablescanner(enable) {
         Object.InvokeMETAFunction('scanner', 'start');
         Object.InvokeMETAFunction('scanner', 'enabled');
         Object.InvokeMETAFunction('scanner', 'autoenter:enabled');
         }
      function InitListener () {
            var elemToCheck = document.getElementById ("ae_plunum");
            if (elemToCheck.addEventListener) { // all browsers except IE before version 9
                elemToCheck.addEventListener ('DOMAttrModified', alert_function, false);    // Firefox, Opera, IE
            }
            if (elemToCheck.attachEvent) {  // Internet Explorer and Opera
                elemToCheck.attachEvent ('onpropertychange', alert_function);   // Internet Explorer
            }
        }          
      </script>
      <script language="javascript" type="text/javascript">
      //will be called from meta tag after autoenter attached to scan,for now runs after button pressed checks to make sure ajax active, then send out query for ae_xrefnum
          function get_plunum() {
              var xmlHttp = false;
              xmlHttp = createXMLHttpRequest();
              //takes response from db and puts it in plunum field
              xmlHttp.onreadystatechange = function () {
                      document.getElementById("ae_plunum").value = xmlHttp.responseText;
                  }
              //sends to php to query
              var ae_xrefnum = document.getElementById("ae_xrefnum").value;
              var querystring = "?ae_xrefnum=" + ae_xrefnum;
              xmlHttp.open("GET", "helloscan2.php" + querystring, true);
              xmlHttp.send(null);
          }
          function createXMLHttpRequest() {
              var xmlHttp = false;
              try {// code for IE7+, Firefox, Chrome, Opera, Safari
                  xmlHttp = new XMLHttpRequest();
              }
              catch (err) {// code for IE6, IE5
                  xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
              }
              return xmlHttp
          }                 
     </script>
</head>
<body onload="enablescanner(true), InitListener();">
    <h3 align="center"><center><img src="ac moore"/></center>Please scan a barcode...</h3>
    <form  name="myform" id="myform">
    ItemBarcode:
    <input type="text" id="ae_xrefnum" ItemBarcode="divE1" /> 
    <!--unhidden for development, once this populates with value from php, will then trigger another function for query-->
    plunum:
    <input type="text" id="ae_plunum"  />
    Sell Price:
    <input type="text" id="ae_sellprice" />
    <!--button here for development, will be removed once i see plunum can be populated-->
    <input type="button"  value="submit me" onclick="get_plunum()" >
    </form>
    <script language=javascript type="text/javascript">
    //focuses on ae_xrefnum when refresh occurs or page loads
        {
          document.myform.ae_xrefnum.focus();
        }
    </script>
</body>
</html>

Link to comment
Share on other sites

did a little thinking and figured it out, hope this helps someone else out.

              //takes response from db and puts it in plunum field
              xmlHttp.onreadystatechange = function () {
                  document.getElementById("ae_plunum").value = xmlHttp.responseText;
                  //once value filled in ae_plunum, this fires the onchange event to get ae_sellprice
                  var targetTxtBox = document.getElementById('ae_plunum');
                  if (targetTxtBox.fireEvent) { // IE Way
                      targetTxtBox.fireEvent('onchange');
                  }
                  else if (document.createEvent) { // Firefox Way
                      var evt = document.createEvent('HTMLEvents');
                      evt.initEvent('change', true, true);
                      targetTxtBox.dispatchEvent(evt);
                  }
                  }

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.