mrdav30 Posted May 27, 2011 Share Posted May 27, 2011 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 https://forums.phpfreaks.com/topic/237681-fill-in-field-after-responsetext/ Share on other sites More sharing options...
mrdav30 Posted May 27, 2011 Author Share Posted May 27, 2011 fyi i can't use onchange or oninput b/c i have to have the ae_plunum field hidden, and therefore they'll never those focus to fire these events Link to comment https://forums.phpfreaks.com/topic/237681-fill-in-field-after-responsetext/#findComment-1221440 Share on other sites More sharing options...
mrdav30 Posted May 28, 2011 Author Share Posted May 28, 2011 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 https://forums.phpfreaks.com/topic/237681-fill-in-field-after-responsetext/#findComment-1221449 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.