This topic is locked

javascript onload info needed

10/12/2010 10:51:01 AM
PHPRunner General questions
T
tedwilder author

hello on your tuto pages I saw this :
var ctrlPrice = Runner.getControl(pageid, 'Price');

var ctrlHorsepower = Runner.getControl(pageid, 'Horsepower');

var ctrlTax = Runner.getControl(pageid, 'Tax');

function func() {

ctrlTax.setValue(0.01parseFloat(ctrlPrice.getValue()) +2 parseFloat(ctrlHorsepower.getValue()));

};

ctrlPrice.on('keyup', func);

ctrlHorsepower.on('keyup', func);
It's intereisting. however in my case I dont have the price in the form directly : the user choose thanks to a lookup table the name of the article. The idarticle is passed but not its price. in my before record event in order to calculate the total I do this :

// recuperation prix article

$sql="select * from article where idarticle=".$values["idarticle"];

$rs=CustomQuery($sql);

$dataarticle=db_fetch_array($rs);

then I retrieve it with $dataarticle["price"]
How in the add page javascript event can i get a dynamic total amount that changes when my user pick a different article in the lookup table?
I would need to lauch an sql request like the one above before I can lauch the javascript I guess.. this way I could use your script.. any idea how I can get the price of my article? I cant change my lookup table because I need to get the id of the article not only the price in first place..(I need the idarticle in my after record event ).
thank you.

Sergey Kornilov admin 10/12/2010

It's possible to execute PHP code and pass the result to Javascript. To do so add 'PHP code snippet' to that page and place the following code there:

// recuperation prix article

$sql="select * from article where idarticle=".$values["idarticle"];

$rs=CustomQuery($sql);

$dataarticle=db_fetch_array($rs);

echo "<script>var price='" . $dataarticle["price"] . "';</script>";


hen in your OnLoad event you can access the value of price variable.

T
tedwilder author 10/13/2010



It's possible to execute PHP code and pass the result to Javascript. To do so add 'PHP code snippet' to that page and place the following code there:

// recuperation prix article

$sql="select * from article where idarticle=".$values["idarticle"];

$rs=CustomQuery($sql);

$dataarticle=db_fetch_array($rs);

echo "<script>var price='" . $dataarticle["price"] . "';</script>";


hen in your OnLoad event you can access the value of price variable.


well it doesnt work.. which is quite normal for what I understand i get this error :

d’erreur 8

Description erreur Undefined variable: values

URL unify.fr.nv1/CTI/fourniture2/test/devis_add.php?

Erreur fichier /var/www/CTI/fourniture2/test/include/devis_events.php

Erreur ligne 429

Requête SQL SELECT idlogo,reseau FROM logo WHERE reseau=''
because it doesnt know $values["idarticle"] ..

I would like on the Add page that it retrieves the price of my article. I put this php snippet on Add page. is there a way to lauch the request once the user has chosen the article in the lookup table ?
the only solution I can think of is using a "button".: execute the php sql request with $param["idarticle"] and then execute the javascript.but that will force the user to clik on button to calculate and populate fields total...

Sergey Kornilov admin 10/13/2010

Well, it's going to be more complicated than that.
Here is an idea of how this can be done in PHPRunner 5.3. Create a view in MySQL and perform all required calculations there. Then setup 'Autofill' option to populate other fields when idarticle is selected from dropdown box.
I would be also useful if you provide more info on what exactly you trying to calculate and where other values are coming from.

T
tedwilder author 10/13/2010

I see what you mean. I just checked 5.3 ( by the way : the "HELP" button under "autofill" doesnt launch the help file ( at least on my system )).

here is the explanation of my little project:

the order_add is the main page of everything. It's like an order page : user chooser a user name from the database ( lookup table to get iduser from table user ) and pick one item from a lookup table that loads iditem from item table. user choose shippingmethod from shipping table ( to add shipping charge based on shipping method), user choose vat from vat table. Also I need stock item from the item user choosed to be checked. ( stock is a field in item table ). *this way: when user pick a product (item) , vat ( default values good normally), shipping method (default should be fine) It will :

  • calculate the vat amount ( table item, field price * vat table, field vat1)
  • Total order amount :add shipping charge ( table shipping, field price ) + result from above.
  • Check table item, field stock : if under let's say 3 warn and send mail to manager, otherwise new stock value = stock - 1
    that's it. it seems quite simple to me although it requires dynamic calculation. autofill seems fine. in order to make it easier I'm gonna do a page out of phprunner system, the page is going to be a simple page on which user choose item and user(customer) and the button will send datas in url like .../order_add.php?iditem=3&iduser=6

    in that case what little code should I use and in what events should I put it to get the datas from the url and use it on my phprunner built page? This way i can use your javascript to calculate tax, and total.

T
tedwilder author 10/15/2010

just to let to user know that they can simply put $_GET["formfield"] in editor under " Default values" . this way it fills the page with data from the form.