Jump to content

[SOLVED] Passing Values Help!


savagenoob

Recommended Posts

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>

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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']

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.