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.

 

 

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.