This topic is locked

DAL method does not work on javascript_onload event?

3/26/2014 11:49:11 PM
PHPRunner General questions
O
overmars author

Dear All,

need your advice...
I just want to ask why DAL method does not work on javascript_onload event?

I need this because I want to read some contents of field in second table.( get price value)

what's the alternative way?
TABLE1 NEWS :

  • NEWS_ID
  • MEDIA_NAME
  • COLOR
  • SIZE
  • AD_VALUE
    TABLE2 MEDIA :
  • MEDIA_ID
  • MEDIA_NAME
  • PRICE_FC
  • PRICE_BW
    ==========================================================
    global $dal; //

    $table2 = $dal->Table("media");

    $rstmp = $table2->Query("MEDIA_NAME='".$values["MEDIA_NAME"]."'","");

    $datatmp = db_fetch_array($rstmp);
    var ctrlLUAS = Runner.getControl(pageid, 'SIZE');

    var ctrlCOLOR = Runner.getControl(pageid, 'COLOR');

    var ctrlAD_VALUE = Runner.getControl(pageid, 'AD_VALUE');

    PRICE1 = $datatmp["PRICE_FC"];

    PRICE2 =$datatmp["PRICE_BW"];
    function func() {
    if ((+ctrlCOLOR.getValue()) == 'Y')

    ctrlAD_VALUE.setValue(PRICE1(+ctrlSIZE.getValue()));

    elseif ((+ctrlCOLOR.getValue()) == 'N')

    ctrlAD_VALUE.setValue(PRICE2
    (+ctrlSIZE.getValue()));
    };

    ctrlSIZE.on('keyup', func);

    ctrlCOLOR.on('keyup', func);
    ==========================

    Thanks.

W
wildwally 3/27/2014

DAL method and fields are server side code and javascript is a client side code the two do not work together at the same time.
You can however pass data from the server to the client (JS).
using the $pageObject -> setProxyValue("name", "value"); & proxy.name
Search help manual for setProxyValue for more details.

O
overmars author 3/29/2014

thanks wildwally,
But, if not mind, could you explain me with a sample how implementation it for my case?

(read contents of a records from the second table)
I've read references about "setProxyValue" but I don't know how to use it.
thanks.



DAL method and fields are server side code and javascript is a client side code the two do not work together at the same time.
You can however pass data from the server to the client (JS).
using the $pageObject -> setProxyValue("name", "value"); & proxy.name
Search help manual for setProxyValue for more details.

Sergey Kornilov admin 3/30/2014

You need to move your DAL code to one of server side events i.e. to BeforeDisplay. In BeforeDisplay event you can execute your SQL query, retrieve values from the database and pass it to Javascript via setProxyValue() function.
Here are code samples:

https://xlinesoft.com/phprunner/docs/setproxyvalue.htm

O
overmars author 4/1/2014



You need to move your DAL code to one of server side events i.e. to BeforeDisplay. In BeforeDisplay event you can execute your SQL query, retrieve values from the database and pass it to Javascript via setProxyValue() function.
Here are code samples:

https://xlinesoft.com/phprunner/docs/setproxyvalue.htm


Hi Admin,
I have to move the DAL code in BeforeDisplay event like this.
global $dal;

$table2 = $dal->Table("media");

$rstmp = $table2->Query("MEDIA_NAME='".$values["MEDIA_NAME"]."'","");

$datatmp = db_fetch_array($rstmp);
Then, in javscript onloadEvent I make setProxyValue() function like this:
));

$pageObject->setProxyValue("PRICE2", ($datatmp["PRICE_BW"]));

function func() {
if ((+ctrlCOLOR.getValue()) == 'Y')

ctrlAD_VALUE.setValue(PRICE1(+ctrlLUAS.getValue()));

elseif ((+ctrlCOLOR.getValue()) == 'N')

ctrlAD_VALUE.setValue(PRICE1
(+ctrlLUAS.getValue()));
};

ctrlLUAS.on('keyup', func);

ctrlCOLOR.on('keyup', func);
is this right? why i find syntax error? can you help me to solve the problem?
thanks

Sergey Kornilov admin 4/1/2014

Still wrong. Please see the manual one more time:

https://xlinesoft.com/phprunner/docs/setproxyvalue.htm
setProxyValue() is a PHP function and needs to be used in server side event like BeforeDisplay.
Then in your Javascript OnLoad event use the suggested syntax in order to access the value passed via proxy object.
Examples of passing data:

$pageObject->setProxyValue("name", "Some value");


Example of retrieving data:

alert(proxy['name']);