This topic is locked
[SOLVED]

 Hide Field Based On Another Fields data

8/20/2016 8:28:36 PM
PHPRunner General questions
M
mhollibush author

I have a form that allows people to pre-register for an event,
I need to hide the "pre-register" field if the "completed" field = Yes
I know its a Javascript OnLoad event, but I can't get it to work
var ctrl = Runner.getControl(pageid, "completed");

pageObj.hideField("register");

if (this.getValue() == "Yes"){

pageObj.hideField("register");

}

else {

pageObj.showField("register");

}

lefty 8/20/2016



I have a form that allows people to pre-register for an event,
I need to hide the "pre-register" field if the "completed" field = Yes
I know its a Javascript OnLoad event, but I can't get it to work
var ctrl = Runner.getControl(pageid, "completed");

pageObj.hideField("register");

if (this.getValue() == "Yes"){

pageObj.hideField("register");

}

else {

pageObj.showField("register");

}



Your missing one line.
var ctrlcategory = Runner.getControl(pageid, 'completed');

var ctrlcategory = Runner.getControl(pageid, 'register');
ctrlcompleted.on('change', function(e){ //if neeeded
if (this.getValue() == 'Yes'){
ctrlregister.hide();

pageobj.hideField("register");
$("tr[data-fieldname='register']").hide();
}else{

}
ctrlregister.show();

$("tr[data-fieldname='register']").show();
});

lefty 8/20/2016



Your missing one line.
var ctrlcompleted = Runner.getControl(pageid, 'completed');

var ctrlregister = Runner.getControl(pageid, 'register');
ctrlcompleted.on('change', function(e){
if (this.getValue() == 'Yes'){
ctrlregister.hide();

pageobj.hideField("register");
$("tr[data-fieldname='register']").hide();
}else{

}
ctrlregister.show();

$("tr[data-fieldname='register']").show();
});



UPDATED 914 EST.

M
mhollibush author 8/20/2016



UPDATED 914 EST.


Believe me, I am extremely new to this.... Thank you for all your help <img src='https://asprunner.com/forums/file.php?topicimage=1&fieldname=reply&id=80117&image=1&table=forumreplies' class='bbc_emoticon' alt=':)' />

M
mhollibush author 8/20/2016



Believe me, I am extremely new to this.... Thank you for all your help <img src='https://asprunner.com/forums/file.php?topicimage=1&fieldname=reply&id=80118&image=1&table=forumreplies' class='bbc_emoticon' alt=':)' />



Still didn't work..

I think this is where I am having issues:
A visitor visits the view page, if the event is still available the pre-register field ( custom field ) will be visible,

But if the Admin marks the event complete - the pre-register field will be hidden
I need the Javascript to see if the field complete is "Yes"

then don't show the pre-register field.
There is no other function on the page as the "complete field" is stored "yes" in the database and not on the form

lefty 8/20/2016



Still didn't work..

I think this is where I am having issues:
A visitor visits the view page, if the event is still available the pre-register field ( custom field ) will be visible,

But if the Admin marks the event complete - the pre-register field will be hidden
I need the Javascript to see if the field complete is "Yes"

then don't show the pre-register field.
There is no other function on the page as the "complete field" is stored "yes" in the database and not on the form


try this on view page on load javascript.
var ctrl = Runner.getControl(pageid, "complete");

var ctrl = Runner.getControl(pageid, "register");
if(ctrl.getValue() != "Yes"); // use proper case
pageObj.hideField("register");
if (this.getValue() !== "Yes"){
pageObj.showField("register")
}
else {
pageObj.hideField("register");
}
IF complete field is not available then you need to grab it in either an inner join on the table you are working on . or before process event with a session variable. OR if complete is available on your table just add it to the view page and let the javascript decide weather to show or hide.

M
mhollibush author 8/20/2016



try this on view page on load javascript.
var ctrl = Runner.getControl(pageid, "complete");

var ctrl = Runner.getControl(pageid, "register");
if(ctrl.getValue() != "Yes"); // use proper case
pageObj.hideField("register");
if (this.getValue() !== "Yes"){
pageObj.showField("register")
}
else {
pageObj.hideField("register");
}
IF complete field is not available then you need to grab it in either an inner join on the table you are working on . or before process event with a session variable. OR if complete is available on your table just add it to the view page and let the javascript decide weather to show or hide.


Making some headway - the field has been hidden, but it always hidden, whether "complete" is "Yes" or empty

lefty 8/20/2016



Making some headway - the field has been hidden, but it always hidden, whether "complete" is "Yes" or empty


//oophs I think this is right
var ctrl = Runner.getControl(pageid, "complete")
if(ctrl.getValue() != "Yes") {
pageObj.showField("register");
}else {
pageObj.hideField("register");
};
//javascript on load on view page ( check syntax before you build )

romaldus 8/21/2016



I have a form that allows people to pre-register for an event,
I need to hide the "pre-register" field if the "completed" field = Yes
I know its a Javascript onload event, but I can't get it to work
var ctrl = Runner.getControl(pageid, "completed");

pageObj.hideField("register");

if (this.getValue() == "Yes"){

pageObj.hideField("register");

}

else {

pageObj.showField("register");

}


The easiest way to do this is in php.

In view page Before Display Event use the following code:

if ($values["completed"]=='YES')
$pageObject->hideField("pre_register");
lefty 8/21/2016

Great Suggestion romaldus . I don't think the completed registration value is available though . He needs to grab it either in query or in check for specific record and update on load. I was thinking the only way to this was query it with an alias or actual field value then javascript onload, but he still can do same with your short code which is a lot quicker and easier to code.

M
mhollibush author 8/21/2016



The easiest way to do this is in php.

In view page Before Display Event use the following code:

if ($values["completed"]=='YES')
$pageObject->hideField("pre_register");



That Worked.... Thank You!!!!

M
Mark Kramer 9/1/2016



Still didn't work..

I think this is where I am having issues:
A visitor visits the view page, if the event is still available the pre-register field ( custom field ) will be visible,

But if the Admin marks the event complete - the pre-register field will be hidden
I need the Javascript to see if the field complete is "Yes"

then don't show the pre-register field.
There is no other function on the page as the "complete field" is stored "yes" in the database and not on the form


As a newbie myself, I use the f12 key in the browser to take me into debug mode. It works pretty well at pointing out what's missing or what's not defined etc...