Welcome to the nuBuilder Forums!
Join our community by registering and logging in.
As a member, you'll get access to exclusive forums, resources, and content available only to registered users.
Join our community by registering and logging in.
As a member, you'll get access to exclusive forums, resources, and content available only to registered users.
conditional show question
conditional show question
Hi
I want to show a question on a subform if the answer on a other question = true.
I can't add any JavaScript on a subform
Is it possible?
Johan
I want to show a question on a subform if the answer on a other question = true.
I can't add any JavaScript on a subform
Is it possible?
Johan
Re: conditional show question
Johan,
The answer is yes.
But...
Can you explain what you want to do a bit more?
Steven
The answer is yes.
But...
Can you explain what you want to do a bit more?
Steven
Re: conditional show question
Steven
I have 2 questions on my subform. If the answer on q1 is yes I want to show question2. Else hide question2
Johan
I have 2 questions on my subform. If the answer on q1 is yes I want to show question2. Else hide question2
Johan
-
- Posts: 785
- Joined: Sun Oct 14, 2018 11:25 am
Re: conditional show question
Johan,
If I understand you correctly, you want hide the entire (second) row if yes is chosen (in select/dropdown ?) in the first row?
If I understand you correctly, you want hide the entire (second) row if yes is chosen (in select/dropdown ?) in the first row?
-
- Posts: 785
- Joined: Sun Oct 14, 2018 11:25 am
Re: conditional show question
Try this:
Add an onclick event handler for you yes/no Field:
Add this code in the main form's JavaScript field:
Add an onclick event handler for you yes/no Field:
Code: Select all
hideSecondRowIfFirstQuestionYes('replacewithyoursubformname','replacewithyouryesnofield');
Code: Select all
function hideSecondRowIfFirstQuestionYes(subform, yesNoField) {
var arr = subGridGetRowArray(subform, yesNoField);
$('#'+subform+'001nuRECORD').css("visibility", (arr[0] == 'yes') ? "visible" : "hidden");
}
// helper function, might be an overkill for your task but useful for other purposes..
function subGridGetRowArray(subform, fieldname) {
var a = Array();
var sf = nuSubformObject(subform);
var c = sf.fields.indexOf(fieldname);
for (var i = 0; i < sf.rows.length; i++) {
if (sf.deleted[i] == 0) {
var rv = sf.rows[i][c];
a.push(rv);
}
}
return a;
}
You do not have the required permissions to view the files attached to this post.
Re: conditional show question
Johan,
You could do this...
Steven
You could do this...
Code: Select all
function showRow(row){
$("[id^='sf'][id$='nuRECORD']").hide(); //-- hide all rows from subform (sf)
$('#sf' + nuPad3(row) + 'nuRECORD').show(); //-- show "row" of subform (sf)
}
Steven
Re: conditional show question
Steven, Toms
Is it correct that your solution will hide the next row of a subform?
I just want to hide another question in the same row of my subform.
Johan
Is it correct that your solution will hide the next row of a subform?
I just want to hide another question in the same row of my subform.
Johan
Re: conditional show question
Johan,
The code above hides all rows and then displays just one - I suggest you try it and then customise it to exactly what you want.
Steven
Code: Select all
function showRow(row){
$("[id^='sf'][id$='nuRECORD']").hide(); //-- hide all rows from subform (sf)
$('#sf' + nuPad3(row) + 'nuRECORD').show(); //-- show "row" of subform (sf)
}
Steven