Does someone have a better way....There has to be a better way.

In a Form application, the user fills out profile information to setup an account. At the bottom of the form they select the product they want to purchase from a pull down (SELECT). The SELECT is filled from a product database that is different from the profile database that the application uses. All of this is easy to work within the Scriptcase application builder. As part of the interface to the user, I wanted to indicate the product number and price of the product the user selects in the pull down by showing this information next to the pull down SELECT. The product number and price are in the product table (not the profile database used by the application).

I could not find a way to make the information from the product database available to ajax or javascript so that the information could be dynamically changed. I ended up creating a SQL query to the database in the OnLoad Event and defining javascript variables with echo() as shown:
// get product records
$product_sql =
“SELECT
ProdType,
ProductNumber,
ProductPrice,
Pass_Tbl_Code
FROM
Products
WHERE
(ProdType = ‘MM’)”;
sc_lookup (mmp, $product_sql, “conn_access_WebDB”);

if({mmp}===false){
echo(’<script>alert(“Access error. Message =”’. {mmp_erro}.’");</script>’);
}
else {
echo(’<script language=“javascript” type=“text/javascript”>’);
echo(‘ProductNumber = new Array();’);
echo(‘ProductPrice = new Array();’);
echo(‘ProductCode = new Array();’);

{mm_count}=count({mmp});
echo('mm_count='.{mm_count}.';');
for ($i=0; $i&lt;{mm_count}; $i++){
	echo('ProductNumber['.$i.']="'.{mmp[$i][1]}.'";');
	echo('ProductPrice['.$i.']="$ "+Math.round('.{mmp[$i][2]}.'*100)/100;');
	echo('ProductCode['.$i.']="'.{mmp[$i][3]}.'";');
}

}
echo(’</script>’);

I then created a field which was paced in the block with and beside the SELECT. The field label and text are initially blank. I then had to run the application and view the source to find out what HTML ID Scriptcase was giving to the SELECT and to the label field I created.

With this information I created a Javascript Edit for OnChange to the SELECT in which I changed the value of the label field that I had created based on the change in value of the SELECT. See below:

var MM_Type=document.getElementById(“id_sc_field_mm_type”).value;

document.getElementById(“id_label_pricedisplay”).innerHTML = “”;

for (i=0; i<mm_count; i++){
if (ProductCode[i] == MM_Type){
document.getElementById(“id_label_pricedisplay”).innerHTML = ProductNumber[i] + " - " + ProductPrice[i];
break;
}
}

This works, but I believe that there has to be a better way to do this more within the standard framework of Scriptcase. I think that I should NOT have to look into the generated source to accomplish this.

Input from any and all would be appreciated.

Yes …

Form Settings / Ajax Events => Create an onChange Event on your Select/Pulldown-Field. In the Code-Editor you write normal php code. Click on “?” at the right upper (editor) side for more documentation …

If you are using scriptcase for select, then change the sql statement to concatenate name, product number and price; so this information is part of the select options and no javascript needed
raj