This topic is locked
[SOLVED]

 Using Ajax to populate form with info dependent on lookup selection

10/25/2006 2:19:28 AM
PHPRunner General questions
jwoker author

I have to populate form fields with values that are dependent on a lookup "link" value. My plan is to use Ajax to accomplish this. I would appreciate some help incorporating the html and javascript into my Jobs_add.php and Jobs_add.htm files or any other files that need modification.

  1. I plan to use the hidden frame method and figure I can put the following into the HEAD section of Jobs_add.htm:
    <frameset rows="100%,0" frameborder="0">

    <frame name=" displayFrame" src=" display.htm" noresize=" noresize" />

    <frame name=" hiddenFrame" src=" about:blank" noresize=" noresize" />

    </frameset>
  2. My js function can be placed in the HEAD section of Jobs_add.htm as well? Will document.getElementById("CustomerID").value return the CustomerID "link value" or "display value" from the lookup dropdown?
    function requestCustomerAddress() {

    var sId = document.getElementById("CustomerID").value;

    top.frames["hiddenFrame"].location = "getcustomeraddress.php?id=" + sId;

    }
  3. Where do I put - onchange=" requestCustomerAddress()" -
    I figure if I can understand this half of the process reading the info back into the form will be evident. Below is some of the code from Jobs_add .htm and .php. Thanks for any help I can get on this.
    <TD style="BACKGROUND-COLOR: #e8fecf" width=279 colSpan=3>

    {build_edit_control field="customerID" value=$value_customerID mode="add"}&nbsp;</TD>
    // processing customerID - start
    $value = postvalue("value_customerID");

    $type=postvalue("type_customerID");

    $value=prepare_for_db("customerID",$value,$type);

    if(!($value===false))

    $avalues["customerID"]=$value;
    // processibng customerID - end

T
thesofa 10/25/2006

Hi jwoker

I asked a similar question some time ago, and after a while, I got this answer from DaleM

Have a look at This Post From DaleM and see if it does what you want.

It is way over my head, but if you get it working, please do an article about how it works, so we can all play...

Cheers

jwoker author 10/25/2006

I had seen that post and thought it was discussing 3.0 not 3.1. Earlier in that thread Jane posted -
"to do what you want you should be familiar with JavaScript.

Here some JavaScript tutorials:

http://www.webcheatsheet.com/javascript/

http://www.w3schools.com/js/default.asp
You need to add some javascript code to the ..._add.php or ..._edit.php file and modify BuildSelectControl function in the include/..._functions.php file."
So I went out and read the js tutorials and then one on Ajax, I went looking for include/..._functions.php file and couldn't find it so I think it was a 3.0 file that didn't make the cut into 3.1. Anyway, here I am hoping to get some help with my questions above.

D
Dale 10/25/2006

jwoker is correct, all the Ajax I have done is with version 3.0. I myself have no clue on where to interject the code in the 3.1.
I must say, the Ajax funtionality has worked great for me. I am using it to populate an invoice with data from the inventory record, and also at the same time populate the invoice schedule details from a Schedule table. Also I have just implemented an Ajax lookup list selection. On another record of mine I needed a picklist to contractor names and addresses. THe file had over 29000 records in it. The time it took to display the page was to to long as phprunner built the 29000+array for the page. Using Ajax, I no longer get this delay. Works great. For me it was a very successful workaround, I didnt much like the idea that users could get a complete list of my contractors just by viewing source code.
DHTMLGoodies was the source for all my Ajax routines.

Admin 10/26/2006

Hi,
please see my answers.

  1. Yes, you can. Not sure I understand your question fully. Please clarify.
  2. To access a field control from Javascript use the following expression.
    editform.value_CustomerId



So if CustomerId is Lookup wizard, use this expression to get currently selected value:

editform.value_CustomerId.options[editform.value_CustomerId.selectedIndex].value



Here is the expression for simple Text field:

editform.value_CustomerId.value


3. To add an onchange to Lookup wizard modify BuildSelectControl function in include\commonfunctions.php file.

Here is the sample code:

if($strTableName=="mytable" && $field=="CustomerId")

{

$onchange="requestCustomerAddress()";

}



insert it just after this line:

$onchange="";


Please note that field and table names are case-sensitive in both Javascript and PHP code snippets.

A
almond 9/17/2007

Good day to all...
These seems to be close to what i am planning to do as well. Has anyone had success in implementing these type of codes in version 4.0??? Hope someone can share how did had it working.
Thanks in advance for the help.
Almond