This topic is locked
[SOLVED]

 Get initial value of a checkbox

10/12/2020 9:01:52 PM
PHPRunner General questions
K
keithh0427 author

Hello all,
I'm trying to obtain the initial value of a checkbox in order to hide/show other elements on the Add page.
I have tried several times and I include some of my attempts below:
var virtual = document.getElementById('edit_field33');

if (virtual.checked == true)

{

ctrlVirtualPremeeting.setEnabled();

ctrlVirtualMeeting.setEnabled();

} else {

ctrlVirtualPremeeting.setDisabled();

ctrlVirtualMeeting.setDisabled();

}
and...
var ctrlVirtual = Runner.getControl(pageid, 'virtualFlag');

if (ctrlVirtual .checked == true)

{

ctrlVirtualPremeeting.setEnabled();

ctrlVirtualMeeting.setEnabled();

} else {

ctrlVirtualPremeeting.setDisabled();

ctrlVirtualMeeting.setDisabled();

}
Neither of these examples worked along with several other attempts.
Can someone help me get on the right path?

K
keithh0427 author 10/13/2020

For future reference, this code worked.
var isChecked = $('#edit_field33').attr('checked')?true:false;

if (isChecked)

{

ctrlVirtualPremeeting.setEnabled();

ctrlVirtualMeeting.setEnabled();

} else {

ctrlVirtualPremeeting.setDisabled();

ctrlVirtualMeeting.setDisabled();

}

Sergey Kornilov admin 10/13/2020

I just wanted to add that if you need to work with PHPRunner's Edit controls using getValue() function is more reliable than referring to those elements by ID like '#edit_field33':

https://xlinesoft.com/phprunner/docs/ctrl_getvalue.htm
If ID changes at some point in the future your code will stop working.

K
keithh0427 author 10/13/2020



I just wanted to add that if you need to work with PHPRunner's Edit controls using getValue() function is more reliable than referring to those elements by ID like '#edit_field33':

https://xlinesoft.com/phprunner/docs/ctrl_getvalue.htm
If ID changes at some point in the future your code will stop working.


Thanks. I agree.
I worked with Fernando and he came up with the same concept as you mentioned. His result is:

var ctrlVirtual = Runner.getControl(pageid, 'virtualFlag');

if (ctrlVirtual.valueElem[0].checked === true)

{

ctrlVirtualPremeeting.setEnabled();

ctrlVirtualMeeting.setEnabled();

} else {

ctrlVirtualPremeeting.setDisabled();

ctrlVirtualMeeting.setDisabled();

}
ctrlVirtual.on('change', function(e) {

if (this.valueElem[0].checked) {

ctrlVirtualPremeeting.setEnabled();

ctrlVirtualMeeting.setEnabled();

} else {

ctrlVirtualPremeeting.setDisabled();

ctrlVirtualMeeting.setDisabled();

}

});