This topic is locked

Calculations

3/26/2010 2:16:28 AM
PHPRunner General questions
G
Greeham author

Hi,
I am a current user of Version 5.0 and am trying out 5.2 and have ran into an issue I am hoping someone can help me with.
Below is a snippet of my visual editor code from version 5.0:-

<TR>

<TD class=shade width=150>Transfer Price (£)</TD>

<TD width=250>{build_edit_control field="transferprice" mode="add" value=$value_transferprice}&nbsp;<INPUT id=calculate class=button onclick=calc() value=Calculate type=button name=calculate></TD>

<TR>

<TD class=shade width=150>Prices Updated On</TD>

<TD width=250>{build_edit_control field="updateddate" mode="add" value=$value_updateddate}</TD>

<TR height=50>

<TD colSpan=2 align=middle><INPUT class=button value=Save type=submit name=submit1><INPUT class=button value=Reset type=reset>&nbsp;{if $onthefly}<INPUT class=button value=Cancel type=button {$cancelonclick}>&nbsp;

{/if}<input type=hidden name="a" value="added"></TD></FORM>

<DIV></DIV><!-- legend -->

<TR height=50>

<TD colSpan=2 align=left>

<DIV align=center>

<HR SIZE=1 width=300 noShade>

</DIV>

<P align=center><BR>&nbsp;</P></TD></TR></TBODY></TABLE>{if !$onthefly}

<P align=center>{include_if_exists file="include/footer.php"}&nbsp;{/if}{$linkdata}<script>SetToFirstControl();</script></P></DIV>{literal}<script language="javascript" type="text/javascript">

function calc() {



// Form fields by name

pp = document.getElementsByName("value_factpricepart");

pl = document.getElementsByName("value_factpricelab");

pt = document.getElementsByName("value_factpricetot");

gbp = document.getElementsByName("value_listpricepound");

ex = document.getElementsByName("value_exchrate");

usd = document.getElementsByName("value_listpricedollar");

tr = document.getElementsByName("value_transferprice");
// Working local vars

var pricePart = parseFloat(pp[0].value);

var priceLab = parseFloat(pl[0].value);

var exchange = parseFloat(ex[0].value);



// Total factory price

var priceFact = (pricePart + priceLab).toFixed(2);

pt[0].value = priceFact;
// GBP price depends on total factory price

var priceGBP;

var factor;



switch(true) {



// £0 - £4.99

case (priceFact >= 0.00 && priceFact <= 4.99):

factor = 20;

break;



// £5.00 - £9.99

case (priceFact >= 5.00 && priceFact <= 9.99):

factor = 10;

break;



// £10.00 - £99.99

case (priceFact >= 10.00 && priceFact <= 99.99):

factor = 4;

break;



// £100.00 + £499.99

case (priceFact >= 100.00 && priceFact <= 499.99):

factor = 2;

break;
// £500.00 + £2499.99

case (priceFact >= 500.00 && priceFact <= 2499.99):

factor = 1.5;

break;
// £2500.00 + £14999.99

case (priceFact >= 2500.00 && priceFact <= 14999.99):

factor = 1.25;

break;
}
priceGBP = parseFloat(priceFact * factor).toFixed(2);

gbp[0].value = priceGBP;



// USD price depends on GBP and exchange rate

var priceUSD = parseFloat(priceGBP * exchange).toFixed(2);
if(isNaN(priceUSD) || priceUSD == null)
{

priceUSD = 0.00;

}
usd[0].value = priceUSD;
// Calculate transfer price - List Pound price less 10%

var priceXFR = parseFloat(priceGBP - ((priceGBP / 100) * 10)).toFixed(2);

tr[0].value = priceXFR;

}

</script>{/literal}</BODY></HTML>


Now this works great for calculating the Transfer Price by pressing the Calculate button, but in version 5.2 this does't work. Below is my code from 5.2:-

{BEGIN transferprice_fieldblock}<TR>

<TD class=shade width=150>{BEGIN transferprice_label}Transfer

Price (£){END transferprice_label}</TD>

<TD width=250>{$transferprice_editcontrol} <INPUT id=calculate class=button onclick=calc() value=Calculate type=button name=calculate>

</TD></TR>{END transferprice_fieldblock}

{BEGIN updateddate_fieldblock}<TR>

<TD class=shade width=150>{BEGIN updateddate_label}Prices

Updated On{END updateddate_label}</TD>

<TD width=250>{$updateddate_editcontrol}

</TD></TR>{END updateddate_fieldblock}</TBODY></TABLE>

<DIV id="buttons_block{$id}"><BR>&nbsp;&nbsp;&nbsp;<A

href="instspares_list.php?a=return" {$backbutton_attrs}>Back to list</A>

<DIV align=left>

<HR SIZE=1 width="100%" noShade>

</DIV>

{BEGIN legend}<DIV id="required_block{$id}"><IMG alt=bullet

src="images/icon_required.gif"> - Required field</DIV>{END legend}{$legendBreak} {BEGIN save_button}<INPUT id="savebutton{$id}" class=button value=Save type=submit {$savebutton_attrs}>{END save_button}

{BEGIN reset_button}<INPUT class=button value=Reset type=reset {$resetbutton_attrs}>{END reset_button}

<SPAN id="span{$id}">&nbsp;</SPAN> {BEGIN prev_button}<INPUT id="prev{$id}" class=button value=" <<< " type=reset {$prevbutton_attrs}>{END prev_button}

{BEGIN next_button}<INPUT id="next{$id}" class=button value=" >>> " type=reset {$nextbutton_attrs}>{END next_button}

</DIV></TD></TR></TBODY></TABLE>{END editForm}{BEGIN detail_tables}{END detail_tables}<BR><BR>{$footer}

<script>SetToFirstControl();</SCRIPT>

<script language=javascript type=text/javascript>

function calc() {



// Form fields by name

pp = document.getElementsByName("value_factpricepart");

pl = document.getElementsByName("value_factpricelab");

pt = document.getElementsByName("value_factpricetot");

gbp = document.getElementsByName("value_listpricepound");

ex = document.getElementsByName("value_exchrate");

usd = document.getElementsByName("value_listpricedollar");

tr = document.getElementsByName("value_transferprice");
// Working local vars

var pricePart = parseFloat(pp[0].value);

var priceLab = parseFloat(pl[0].value);

var exchange = parseFloat(ex[0].value);



// Total factory price

var priceFact = (pricePart + priceLab).toFixed(2);

pt[0].value = priceFact;
// GBP price depends on total factory price

var priceGBP;

var factor;



switch(true) {



// £0 - £4.99

case (priceFact >= 0.00 && priceFact <= 4.99):

factor = 20;

break;



// £5.00 - £9.99

case (priceFact >= 5.00 && priceFact <= 9.99):

factor = 10;

break;



// £10.00 - £99.99

case (priceFact >= 10.00 && priceFact <= 99.99):

factor = 4;

break;



// £100.00 + £499.99

case (priceFact >= 100.00 && priceFact <= 499.99):

factor = 2;

break;
// £500.00 + £2499.99

case (priceFact >= 500.00 && priceFact <= 2499.99):

factor = 1.5;

break;
// £2500.00 + £14999.99

case (priceFact >= 2500.00 && priceFact <= 14999.99):

factor = 1.25;

break;
}
priceGBP = parseFloat(priceFact * factor).toFixed(2);

gbp[0].value = priceGBP;



// USD price depends on GBP and exchange rate

var priceUSD = parseFloat(priceGBP * exchange).toFixed(2);
if(isNaN(priceUSD) || priceUSD == null)
{

priceUSD = 0.00;

}
usd[0].value = priceUSD;
// Calculate transfer price - List Pound price less 10%

var priceXFR = parseFloat(priceGBP - ((priceGBP / 100) * 10)).toFixed(2);

tr[0].value = priceXFR;

}

</SCRIPT>

{END body}</BODY></HTML>


Could someone point me in the right direction as to what has changed between versions?
Thanks,
Graham

Sergey Kornilov admin 3/26/2010

In PHPRunner 5.2 you need to use Javascript API in order to access control values:

http://xlinesoft.com/phprunner/docs/javascript_api.htm
For example to read the current value of exchrate field use the following:
var ctrl = Runner.getControl(pageid, 'exchrate');

var value = ctrl.getValue();
We recommend to add this code to 'Javascript: OnPageLoad' event that accepts pageid as a parameter.