This topic is locked

Hiding fields based on input

10/6/2010 4:27:42 PM
PHPRunner General questions
K
karmacomposer author

How do you hide a field based on the choice of another field in the same table?
Mike

Sergey Kornilov admin 10/6/2010

You need to use Javascript API for this purpose:

http://xlinesoft.com/phprunner/docs/javascript_api.htm
Check 'Show dropdown list of US states if US was selected in country list' example.

K
karmacomposer author 10/6/2010



You need to use Javascript API for this purpose:

http://xlinesoft.com/phprunner/docs/javascript_api.htm
Check 'Show dropdown list of US states if US was selected in country list' example.


Excellent. That is perfect. Thank you.
Mike

K
karmacomposer author 10/7/2010

OK, so I have a dropdown at the start of the form. You can choose to be SWT or CC.
If the person chooses CC, I need to hide 1 field.
Here is the Javascript code (I think) that may work, but not sure:
// hide control

var ctrl = Runner.getControl(CandidateSWTID, 'CandidateSWT');

ctrl.hide('Proof of Student Status')
The field that has to be hidden is called 'Proof of Student Status' - not sure where to put that in the Javascript code.
However, this is an onload event, (right?) and the field needs to be hidden after they make the choice, not just when the form loads.
How would I do this?
I am also not sure how to code the if statement (if the field=cc then do this)
Mike

Sergey Kornilov admin 10/7/2010

Mike,
you need to take a closer look at this example:

http://xlinesoft.com/phprunner/docs/show_dropdown_list_of_us_states.htm
If you are looking for a way to show or hide one of controls based on value of another control - you have to start by creating variables for both controls.

S
smith 10/8/2010

Dear admin

How to do the same with check-box value instead of a drop down value

example if checked = show the field else hide, I tried with (this.getValue() == 'true') and (this.getValue() == '1') but no luck
smith



Mike,
you need to take a closer look at this example:

http://xlinesoft.com/phprunner/docs/show_dropdown_list_of_us_states.htm
If you are looking for a way to show or hide one of controls based on value of another control - you have to start by creating variables for both controls.

woodey2002 10/8/2010

Hi Smith

-----------

if (ctrl"your control name".getValue()=='on'){

-----------
Hope this helps,
James
Phprunners No1 Fan

S
smith 10/8/2010

Thank you James, But the code is not working

my code is pasted below..
var ctrlCountry = Runner.getControl(pageid, 'Escort_requirement');

var ctrlState = Runner.getControl(pageid, 'escort');
ctrlCountry.on('change', function(e){

if (ctrl 'Escort_requirement'.getValue()=='on'){

ctrlState.show();

}else{

ctrlState.hide();

}

});
is it fine?



Hi Smith

-----------

if (ctrl"your control name".getValue()=='on'){

-----------
Hope this helps,
James
Phprunners No1 Fan

A
ann 10/8/2010

Smith,
here is the correct syntax for the line:

if (ctrlCountry.getValue()=='on'){
S
smith 10/8/2010

NO LUCK,

code used

var ctrlCountry = Runner.getControl(pageid, 'Escort_requirement');

var ctrlState = Runner.getControl(pageid, 'escort');

ctrlCountry.on('change', function(e){

if (ctrlCountry.getValue()=='on'){

ctrlState.show();

}else{

ctrlState.hide();

}

});



Smith,
here is the correct syntax for the line:

if (ctrlCountry.getValue()=='on'){


A
ann 10/8/2010

Smith,
here is a helpful thread on how to hide fields:

http://www.asprunner.com/forums/topic/15378-how-to-hide-controls-on-addedit-pages/pagehlhidediv1fromsearch1
Also make sure field names are correct (JavaScript is case sensitive).