This topic is locked
[SOLVED]

PHPRunner 10.91 - some javascript code not working for me.

3/12/2025 8:12:33 PM
PHPRunner General questions
D
DealerModules authorDevClub member

I am creating a dynamic form.
In this form the first field, "form_type" is a radio button lookup field that contains four values.
What I am trying to accomplish is when the user opens the add form and selects one of the radio buttons from this field, it will either hide or show fields on the form.

I have put the following javascript code in the JavaScript Onload Event:

// Make sure the page is fully loaded before running the script
window.onload = function() {
// Get the value of the field, form_type
var formTypeValue = pageObj.getFieldValue('form_type');

// List of dynamic fields to hide/show. There are additional fields that apply to all cases so I am not make changes to those, just the following dynamic fields.
var fieldsToHide = [
'mouse',
'monitor',
'monitor_extension',
'printer',
'microsoft_office',
'usb_hub_extension',
'wireless_mouse_keyboard',
'additional_monitor',
'monitor_number',
'desktop_pc',
'laptop',
'special_printer',
'additional_memory'
];

// If the value of form_type is 'I.T. SUPPORT', 'TERMINATION', or 'NEW HIRE', hide all fields
if (formTypeValue == 'I.T. SUPPORT' || formTypeValue == 'TERMINATION' || formTypeValue == 'NEW HIRE') {
fieldsToHide.forEach(function(field) {
pageObj.hideField(field);
});
} else if (formTypeValue == 'PURCHASE REQUEST') {
// If the value is 'PURCHASE REQUEST', show all fields
fieldsToHide.forEach(function(field) {
pageObj.showField(field);
});
}
};

Perhaps the javascript above does not work within phprunner because I am not using a PHPRunner function that is needed?

Anyone's help is greatly appreciated.

Thanks in advance.
Paul

C
copper21 3/13/2025

The online manual will help you more with this, but here is the jist of what you can do:

//Create form_type variable
var form_type = Runner.getControl(pageid, 'form_type');

//Create hide/show field variables
var mouse = Runner.getControl(pageid, 'mouse');
var monitor = Runner.getControl(pageid, 'monitor');
var monitor_extension = Runner.getControl(pageid, 'monitor_extension');

//Get value selected
form_type.on('change', function(){
if (this.getValue() == 'I.T. SUPPORT' || this.getValue() == 'TERMINATION' || this.getValue() == 'NEW HIRE'){
pageObj.hideField('mouse');
pageObj.hideField('monitor');
pageObj.hideField('monitor_extension');
}
else {
pageObj.showField('mouse');
pageObj.showField('monitor');
pageObj.showField('monitor_extension');
} });

D
DealerModules authorDevClub member 3/14/2025

I appreciate your time in reviewing my code. The code that you presented worked perfectly!
Thanks again.
Paul