This topic is locked

select a field with javascript

11/15/2008 3:17:56 PM
PHPRunner General questions
E
ellesse author

Hi,

I have a table products with fields idprod,price1,price2,price3

Then I have detail invoice with fields idproduct, idprice, price.
I insert idproduct with lookup into table products and idprice a number from 1 to 3.

How (in edit form with javascript) I can have in the field "price" the value of price1 if idprice=1, price2 if idprice=2, price3 if idprice=3
thank you.

J
Jane 11/17/2008

Hi,
use custom JavaScript code for that. However this task requires a lot of custom coding.
As workaround you can fill price field in the Before record added/updated event on the Events tab.

Here is a sample:

$str = "select price1,price2,price3 from products where idprod=".$values["idproduct"];

$rs = db_query($str,$conn);

$data = db_fetch_array($rs);

if ($values["idprice"]==1)

$values["price"] = $data["price1"];

if ($values["idprice"]==2)

$values["price"] = $data["price2"];

if ($values["idprice"]==3)

$values["price"] = $data["price3"];