This topic is locked

Javascript Onload on view page, hiding rows on condition

12/1/2016 8:49:25 PM
PHPRunner General questions
Z
Zerobaka author

Greetings, fellow scripter.
While using view page, i need to hide/show certain row (label-value) based on whenever it has valid value.

This table shows order-price, and using this script:



alert ("START BAH!!!");
var cPrice2 = Runner.getControl(pageid, 'price2');

var cPrice3 = Runner.getControl(pageid, 'price3');

var cPrice4 = Runner.getControl(pageid, 'price4');

var cPrice5 = Runner.getControl(pageid, 'price5');

var cPrice6 = Runner.getControl(pageid, 'price6');

var cPrice7 = Runner.getControl(pageid, 'price7');

var cPrice8 = Runner.getControl(pageid, 'price8');

var cDisc = Runner.getControl(pageid, 'disc_total');
alert ("MID 1 BAH!!!");
var h2 = cPrice2.getValue();

var h3 = cPrice3.getValue();

var h4 = cPrice4.getValue();

var h5 = cPrice5.getValue();

var h6 = cPrice6.getValue();

var h7 = cPrice7.getValue();

var h8 = cPrice8.getValue();

var dt = cDisc.getValue();
alert ("MID 2 BAH!!!");
if (h2 == 0) $("tr[data-fieldname='order2']").hide();

if (h3 == 0) $("tr[data-fieldname='order3']").hide();

if (h4 == 0) $("tr[data-fieldname='order4']").hide();

if (h5 == 0) $("tr[data-fieldname='order5']").hide();

if (h6 == 0) $("tr[data-fieldname='order6']").hide();

if (h7 == 0) $("tr[data-fieldname='order7']").hide();

if (h8 == 0) $("tr[data-fieldname='order8']").hide();

if (dt == 0) $("tr[data-fieldname='disc_total']").hide();
alert ("END BAH!!!");


The alert window only shows till MID 1. In other words, only the first block of the script was successfully executed.

I dont know whats wrong, i think i follows the guide and examples from PHPrunner help.
So, any thoughts will be greatly appreciated.

Thanks.

Admin 12/2/2016

Most likely one of field names is misspelled. Check this troubleshooting guide:

http://xlinesoft.com/phprunner/docs/troubleshooting_javascript_errors.htm

Z
Zerobaka author 12/5/2016



Most likely one of field names is misspelled. Check this troubleshooting guide:

http://xlinesoft.com/phprunner/docs/troubleshooting_javascript_errors.htm


Thanks for the reply, mr Admin. It's a bit confusing, but i'll try to learn them.

Admin 12/5/2016

The fact that first alerts pops up and second one doesn't means that some Javascript error happens between them and most likely one of fields names is misspelled.

Z
Zerobaka author 12/16/2016

Hey everyone, i finally trying it with Chrome's developer tools, and this is the respond:



Uncaught TypeError: cPrice2.getValue is not a function

at constructor.<anonymous> (pageevents_invoice_tagihan.js:183)

at Runner.util.Event.fire (RunnerAll.js:103)

at constructor.fireEvent (RunnerAll.js:209)

at constructor.<anonymous> (RunnerAll.js:19395)

at constructor.goInitQueue (RunnerAll.js:20920)

at Object.initPage (RunnerAll.js:19402)

at Object.initPages (RunnerAll.js:19233)

at constructor.<anonymous> (RunnerAll.js:430)

at constructor.<anonymous> (RunnerAll.js:31)

at Runner.util.Event.fire (RunnerAll.js:103)

(anonymous) @ pageevents_invoice_tagihan.js:183

fire @ RunnerAll.js:103

fireEvent @ RunnerAll.js:209

(anonymous) @ RunnerAll.js:19395

goInitQueue @ RunnerAll.js:20920

initPage @ RunnerAll.js:19402

initPages @ RunnerAll.js:19233

(anonymous) @ RunnerAll.js:430

(anonymous) @ RunnerAll.js:31

fire @ RunnerAll.js:103

fireEvent @ RunnerAll.js:209

postLoad @ RunnerAll.js:670

postLoadFunction @ RunnerAll.js:605


Frankly, it does not making sense, getValue should be a methods available on every control, why is this error happens?

Any idea?
Oh by the way, i found another method to reach my goal, instead using 'Javascript Onload' event,

I use 'Before display' event, and with this:



// Hide empty orders

$rec = $pageObject->getCurrentRecord();

if ($rec['order2']=="-")

$xt->assign("order2_fieldblock", false);

if ($rec['order3']=="-")

$xt->assign("order3_fieldblock", false);

if ($rec['order4']=="-")

$xt->assign("order4_fieldblock", false);

if ($rec['order5']=="-")

$xt->assign("order5_fieldblock", false);

if ($rec['order6']=="-")

$xt->assign("order6_fieldblock", false);

if ($rec['order7']=="-")

$xt->assign("order7_fieldblock", false);

if ($rec['order8']=="-")

$xt->assign("order8_fieldblock", false);

if ($rec['disc_total']==0)

$xt->assign("disc_total_fieldblock", false);


And it works!! But i still wish to know why my javascript failed. Any input will be appreciated.

Thanks guys.

Admin 12/19/2016

Your Javascript most likely one of field names is misspelled in your code.

Z
Zerobaka author 12/20/2016



Your Javascript most likely one of field names is misspelled in your code.


But which one? I check and re-check all field names are correct. And how much i see them,

all variable/object was spelled correctly starting from it's declaration.
Mr admin, you see the script i use, is there any line contains mis-spelled?

Please share it with me if you do?