mrdav30 Posted May 26, 2011 Share Posted May 26, 2011 ok, so i've been bugging everyone on these forums for awhile, and i appreciate everyones help. i'm so close to finishing this, but i'm stuck once again. <html> <head> <title>helloscan</title> <!--refreshes page in seconds--> <meta http-equiv="refresh" content="50"> <!--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'); } </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(); xmlHttp.onreadystatechange = function () { handleStateChange(xmlHttp); } //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 } function handleStateChange(xmlHttp){ //receives data from server, and puts repsonse in ae_plunum field if (xmlHttp.readystate == 4 && xmlHttp.status == "complete") { document.myform.ae_plunum.value = xmlHttp.responseText; } } </script> </head> <body onload="enablescanner(true)"> <h3 align="center"><center><img src="ac moore" /></center>Please scan a barcode...</h3> <form name="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" value="" oninput="get_price()" /> <!--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> //focuses on ae_xrefnum when refresh occurs or page loads { document.myform.ae_xrefnum.focus(); } </script> </body> </html> I'm finally getting the response i need from my php file, but document.myform.ae_plunum.value = xmlHttp.responseText; doesn't fill in the ae_plunum field. any insight would be much appreciated. Quote Link to comment https://forums.phpfreaks.com/topic/237584-using-responsetext-to-fill-in-field/ Share on other sites More sharing options...
sunfighter Posted May 27, 2011 Share Posted May 27, 2011 MrDav for such a short amount of code you have a lot of errors. You are using deleted tags which will only give you problems in the long run and will break your program in various browsers. I suggest you go to http://validator.w3.org/ and fix your problems For the 'will not write' problem change this function: function handleStateChange(xmlHttp){ //receives data from server, and puts repsonse in ae_plunum field if (xmlHttp.readyState == 4 && xmlHttp.status == 200) { document.getElementById('ae_plunum').value = xmlHttp.responseText; } } Quote Link to comment https://forums.phpfreaks.com/topic/237584-using-responsetext-to-fill-in-field/#findComment-1221149 Share on other sites More sharing options...
mrdav30 Posted May 27, 2011 Author Share Posted May 27, 2011 yea i though that would work to, but it doesn't. I did fix some of the errors in my code, but this is ment for an MK500, an item scanner, using it's pocket brower application. Any one else have any idea why this isn't working? Everything i've looked through said this should populate this field but it won't Quote Link to comment https://forums.phpfreaks.com/topic/237584-using-responsetext-to-fill-in-field/#findComment-1221270 Share on other sites More sharing options...
fugix Posted May 27, 2011 Share Posted May 27, 2011 i believe that in order to grab the value of the input you need to change this <input type="text" id="ae_xrefnum" itembarcode="divE1" /> to this <input type="text" name="ae_xrefnum" itembarcode="divE1" /> Quote Link to comment https://forums.phpfreaks.com/topic/237584-using-responsetext-to-fill-in-field/#findComment-1221334 Share on other sites More sharing options...
mrdav30 Posted May 27, 2011 Author Share Posted May 27, 2011 thanks fugix, but i can grab the value from ae_xrefnum, and it goes to my php script to query, and returns the correct result according to firebug, but what i need is for that result to populate my other field, ae_plunum. I was messing around with the javascript debugger, and it breaks at xmlHttp.onreadystatechange = function () { handleStateChange(xmlHttp); }; but it doesn't call on that function for some reason. Quote Link to comment https://forums.phpfreaks.com/topic/237584-using-responsetext-to-fill-in-field/#findComment-1221348 Share on other sites More sharing options...
mrdav30 Posted May 27, 2011 Author Share Posted May 27, 2011 i did it! i had to get rid of if (xmlHttp.readystate == 4) i can't belive that's what has been causing me all these problems, thanks everyone for you help! Quote Link to comment https://forums.phpfreaks.com/topic/237584-using-responsetext-to-fill-in-field/#findComment-1221359 Share on other sites More sharing options...
fugix Posted May 28, 2011 Share Posted May 28, 2011 why should that be causing errors? you need that if statement to check if your response is ready...however it should read if(XMLHttp.readyState == 4) Quote Link to comment https://forums.phpfreaks.com/topic/237584-using-responsetext-to-fill-in-field/#findComment-1221562 Share on other sites More sharing options...
sunfighter Posted May 29, 2011 Share Posted May 29, 2011 @fugix What he posted here must be different from what he is really using. I downloaded his posted code and the function I gave him makes his code work. He says it don't, so I'm guessing we have some differences somewhere. Quote Link to comment https://forums.phpfreaks.com/topic/237584-using-responsetext-to-fill-in-field/#findComment-1221952 Share on other sites More sharing options...
fugix Posted May 29, 2011 Share Posted May 29, 2011 just looked at the function you posted...will work if used correctly...mrdav are you still needing assistance with this? Quote Link to comment https://forums.phpfreaks.com/topic/237584-using-responsetext-to-fill-in-field/#findComment-1222029 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.