Jump to content

calling php and get the selection and transfer back to the originating php


kwstephenchan

Recommended Posts

 

Hi all.

 

I intend to have an input field in PHP program 1. Besides this input field, I have a button so that the user can search for value to be used instead of inputing.  On pressing this button, another php program, say program 2 will be called. Program 2 will go to the database and list the values for selection.  The user can then select and the selected value will be passed back to program 1 (without refreshing other fields in program 1)

 

Can anyone advise how this can be done?

 

I tried using Ajax, but it does not seem to be doing the trick, wonder what have I done wrong.

 

Thanks

 

Followings are the code bit:

 

***** javascript definition ****

<script type="text/javascript">

var XMLHttpRequestObject = false;

if (window.XMLHttpRequest)

{

  XMLHttpRequestObject = new XMLHttpRequest();

}

else if (window.ActiveXObject)

{

  XMLHttpRequestObject = new ActiveXObject("Microsoft.XMLHttp");

}

 

function getData(srcPHP, parm)

{

  var url = srcPHP+"?parm=" + parm;

  if(XMLHttpRequestObject)

  {

    XMLHttpRequestObject.open("GET", url, true);

    XMLHttpRequestObject.onreadystatechange = function()

    {

      if (XMLHttpRequestObject.readyState == 4 &&

          XMLHttpRequestObject.status == 200)

      {

        eval(XMLHttpRequestObject.responseText);

      }

    }

    XMLHttpRequestObject.send(null);

  }

}

 

function alerter(divID,pvalue)

{

  alert(' back toJavaScript');

  var showDiv = document.getElementById(divID);

  showDiv.innerHTML = pvalue;

}

</script>

 

**** parts of program calling the Javascript ****

            <tr valign="baseline">

                        <div width="40%" height="20" align="right" class="lbtxt">Owner : </div>

                        <div height="20" class="intxt">

                          <input name="m_ownerid" type="text" id="m_ownerid" size="4">

                          <font color="#ffffff"><?php $divID="m_ownerid"; $srcData="data.php"; $str="<img src='images/moredot.gif'>"; echo '<a href=javascript:getData(\''.$srcData.'\',\''.$divID.'\') >'.$str.'</a>';

?>*</font></div>

 

    </tr>

 

 

***** code content in data.php ****

<?php

  $parm = $_GET['parm'];

  $pvalue="passing value";

  echo 'alerter(\''.$parm.'\',\''.$pvalue.'\')';

//  echo '<a href=javascript:getData(\''.$srcData.'\',\''.$divID.'\') >'.$str.'</a>';

?>

<?php /*

<html>

<body>

<table>

<tr>

<td> this is the html part </td>

</tr>

</table>

</body>

</html>

*/

?>

 

As noted, I have commented out the html part because if I leave them in, I'll get page error.

As I am new to Ajax, wonder if it is true that the second PHP program cannot have HTML in it.

 

Thanks for all the help.

 

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.