This topic is locked

How to add Javascript event to checkbox field?

4/22/2010 10:04:43 AM
PHPRunner General questions
G
gawde author

Using PHPRunner 5.2 (5242)
I am looking for a way to add an "onclick" javascipt event to a checkbox field. I'm sure it can be done within the phpRunner events and/or code snippet inserts on the Editor page. I have found that 5.2 is using quite a different approach in handling the "edit control" creation for fields than 5.1 was and the methods I previously used no longer apply. I reviewed the 5.2 Javascript API documentation but found nothing specific to adding events.
Has anyone done this yet in 5.2? An example or an extended explanation of the API doc would be much appreciated.
Greg

Admin 4/22/2010

Greg,
you might be missing something.
An excerpt from http://xlinesoft.com/phprunner/docs/javascript_api.htm

Working with the controls


  1. Add an event to the control and transfer the array of arguments to the handler:


There is also an example of adding onClick event handler.

G
gawde author 4/22/2010



Greg,
you might be missing something.
An excerpt from http://xlinesoft.com/phprunner/docs/javascript_api.htm
There is also an example of adding onClick event handler.



Thanks Sergey.
I created and added the following code in the "Javascript OnLoad event" of the table containing the field I wish to affect.
var ctrlTerms = Runner.getControl(pageid, 'cust_termsck');

ctrlTerms.on('click', function(e, argsArr){

this.setValue(argsArr[0]);

},{args: ['btnDisable();']});
I must still be missing something. The intent is to enable/disable a button when the field is checked (the javascript function 'btnDisable()' does that). The only thing that changed after I added the above is that the checkbox will not accept the check.

Still looking for a little help.

Greg

Admin 4/22/2010

I think you need to move function call from arguments section to function body i.e.

var ctrlTerms = Runner.getControl(pageid, 'cust_termsck');

ctrlTerms.on('click', function(e, argsArr){

this.setValue(argsArr[0]);

btnDisable();

},{args: ['newValue']});
G
gawde author 4/23/2010



I think you need to move function call from arguments section to function body i.e.

var ctrlTerms = Runner.getControl(pageid, 'cust_termsck');

ctrlTerms.on('click', function(e, argsArr){

this.setValue(argsArr[0]);

btnDisable();

},{args: ['newValue']});




I revised the javascript as suggested above and here's what is now occuring. The btnDisable() functions seems to be activated now but it takes a couple of clicks to make it happen. The checkbox itself still does not accept the check.
I experimented a bit by changing the 'cust_termsck' field name to the actual html input name 'value_cust_termsck_1'. This corrects the checkbox to accept and show the check but the function is not activated. I displayed the values/status of the field and button from within the btnDisable() function and everything displayed as expected. I can't see any other options to try.