savagenoob Posted January 30, 2009 Share Posted January 30, 2009 I am not good with JS but need to use it with this activex control to activate scanners. It works fine but I need to pass the ClientID and Description from the form but it uses AJAX or something to post to the file that uploads to database. How can I modify it to pass these 2 values... <SCRIPT LANGUAGE="javascript"> function btnScan_onclick() { frmScan.DynamicWebTwain1.SelectSource(); frmScan.DynamicWebTwain1.AcquireImage(); } function btnUpload_onclick() { if(frmScan.txtImageName.value == "") { alert("The Image name can not be empty"); return; } var strActionPage; var strHostIP; var strImageName; var CurrentPathName = unescape(location.pathname); // get current URL in plain ASCII var CurrentPath = CurrentPathName.substring(0, CurrentPathName.lastIndexOf("/") + 1); strActionPage = CurrentPath + "/SaveToDB/SaveToDB.php"; //the ActionPage's file path strHostIP = "snapmanagerpro.com"; strImageName = frmScan.txtImageName.value + ".JPG"; frmScan.DynamicWebTwain1.HTTPPort = 80; //the web service's port frmScan.DynamicWebTwain1.HTTPUploadAsJPEGThroughPost(strHostIP, strActionPage, strImageName); if (frmScan.DynamicWebTwain1.ErrorCode != 0) //Failed to upload image alert(frmScan.DynamicWebTwain1.ErrorString); else //Successful frmScan.submit(); } </SCRIPT> <form id="frmScan" action = "Scan.php"> Image Name: <input type="text" name="txtImageName" size="25"> Description: <input type="text" name="description" size="25"> <input type="hidden" name="ClientID" value="<?php echo $ClientID; ?>" <input type="button" value="Scan" ID = "btnScan" onclick="return btnScan_onclick()"> <input type="button" value="Upload" ID = "btnUpload" onclick="return btnUpload_onclick()"> </table> </form> Quote Link to comment Share on other sites More sharing options...
Psycho Posted January 30, 2009 Share Posted January 30, 2009 Pass the variables to "what" exactly? I don't see any AJAX code in what you posted. There are two main functions that appear to have some custom commands in them (e.g. frmScan.DynamicWebTwain1.SelectSource(). I assume those commands are defined elsewhere. I don't know anything about those custom commands or how you would implement those variables into them. Maybe they aren't even built to accept parameters. I can show you how to pass the form values to those two main functions though. It's up to you what you do with them from that point. Add 'this.form' to the onclick events like this <input type="button" value="Scan" ID = "btnScan" onclick="return btnScan_onclick(this.form)"> <input type="button" value="Upload" ID = "btnUpload" onclick="return btnUpload_onclick(this.form)"> Then change the two main functions to accept a parameter like this function btnScan_onclick(formObj) function btnUpload_onclick(formObj) Within those two functions you can now access the values on the form in this manner: formObj.elements['FIELDNAME'].value Quote Link to comment Share on other sites More sharing options...
savagenoob Posted January 30, 2009 Author Share Posted January 30, 2009 OK, sweet, whatever this JS is doing it is sending the uploaded data to SavetoDB.php but the form action is going to Scan.php. Can I capture the form data in SavetoDB.php with $_POST? Quote Link to comment Share on other sites More sharing options...
Psycho Posted January 30, 2009 Share Posted January 30, 2009 Append the variables to the URL and access them on the receiving page via $_GET Using the process I described above to get the form object in the function you would do something like this: var clientID = formObj.elements['ClientID'].value; var desc = formObj.elements['description'].value; strActionPage = CurrentPath + "/SaveToDB/SaveToDB.php?cid=" + clientID + '&desc=" + desc; Then when the page SaveToDB.php is called you can access those values in the page using $_GET['cid'] & $_GET['desc'] Quote Link to comment Share on other sites More sharing options...
savagenoob Posted January 30, 2009 Author Share Posted January 30, 2009 You are DA MAN! Made my day, thank you for the help. Quote Link to comment 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.