Focal Point
[CLOSED] Hide empty checkboxes with Javascript?

This topic can be found at:
https://forums.informationbuilders.com/eve/forums/a/tpc/f/7971057331/m/8077035595

December 17, 2010, 05:43 PM
PeterV
[CLOSED] Hide empty checkboxes with Javascript?
Hi. I'm stuck finding an answer to this question, and I hope it's pretty simple.

We have a template page on one of our dashboards that populates a checkbox list with facilities that correlate with certain measures that internal customers are evaluating.

Some measures do not have associated facilities. When this occurs, and the page loads, it renders two blank checkboxes.

One is tied to the 'ALL' function (Having a SELECT ALL as a checkbox list item.), and one is blank, correlating to the empty data set.

Can I hide the empty checkboxes? I can't figure out how to write javascript that can actually find this control on the page load, but I can't imagine that it's impossible. I'm assuming that I just don't understand something.

I tried something simple like this:
if(document.YourFormName.TheCheckboxName.checked = true){
document.YourFormName.TheCheckboxName.style.display = 'none';
}

But that fails, as one box is checked, one isn't. Is there a way to grab the control before it renders to the page, see if the XML list generated by a FEX is empty for the returned measure, and then just hide the controls?

I couldn't find anything here on the IBI forums, and I've been reading Javascript support forums to no avail. Figured I might as well try and see if anyone here had a handy solution to try.

Thanks very much!

This message has been edited. Last edited by: Kerry,


WebFOCUS v. 7.6.10
___________________
Win2k3 Server
Intel Xeon 2.3Ghz/4Gb Ram Apache / IIS / SQL Srvr 2005
December 18, 2010, 10:23 AM
ABT
Peter,
I have done something similar in toggling on/off a series of checkboxes and labels into 'Steps'. Maybe this will help:

function window_onload() {

	// WF Default.  Let it do it's thing
	UpdateData();


	// My Stuff - Update *after* WF does it's thing, not before.
	
displayDefault();

}




function displayDefault() {

	// On load, this sets the page to where I want it to be, only show step 1.
	showStep1();
    // Toggle on
	hideStep2();
    // Toggle off
	hideStep3();
    // Toggle off -- See below
	hideStep4();
    // Toggle off
}


function hideStep3() {
	// My label and checkbox group are named (creatively enough) 'Step3' and 'Text3'
	document.getElementById('text3').style.visibility='hidden';
	document.getElementById('step3').style.visibility='hidden';
}



This should point you right.

- ABT


------------------------------------
WF Environment:
------------------------------------
Server/Client, ReportCaster, Dev Studio: 7.6.11
Resource Analyzer, Resource Governor, Library, Maintain, InfoAssist
OS: Windows Server 2003
Application/Web Server: Tomcat 5.5.25
Java: JDK 1.6.0_03
Authentication: LDAP, MRREALM Driver
Output: PDF, EXL2K, HTM

------------------------------------
Databases:
------------------------------------
Oracle 10g
DB2 (AS/400)
MSSQL Server 2005
Access/FoxPro
December 20, 2010, 06:55 PM
PeterV
Hey, thanks so much for the reply! I'll take your suggestions and will go play around with it to see if I can get it to work!

Appreciate it very much Smiler


WebFOCUS v. 7.6.10
___________________
Win2k3 Server
Intel Xeon 2.3Ghz/4Gb Ram Apache / IIS / SQL Srvr 2005
December 21, 2010, 03:47 AM
Tony A
Peter,

The following is some code that I posted in 2006 which gives nothing but the basics of what you need to do -

<html>
 <head>
  <title>Collapsing Divs</title>
 </head>
 <body>
  <div id="div1" style="display: block; background:#f0f5ff; color:#ff0000;">
   This is Div 1
  </div>
  <div id="div2" style="display: block; background:#f0f5ff; color:#ff0000;">
   This is Div 2
  </div>
  <a href="javascript:toggle_div('div1');" alt="Toggle Div 1">Show/Hide Div 1</a><br />
  <a href="javascript:toggle_div('div2');" alt="Toggle Div 2">Show/Hide Div 2</a> 
 </body>
 <script language=javascript>
  function toggle_div(obj) {
     var el = document.getElementById(obj);
     el.style.display = (el.style.display != "block") ? "block" : "none";
  }
 </script>
</html>

T



In FOCUS
since 1986
WebFOCUS Server 8.2.01M, thru 8.2.07 on Windows Svr 2008 R2  
WebFOCUS App Studio 8.2.06 standalone on Windows 10 
December 23, 2010, 12:57 PM
PeterV
Hi Tony, thanks for responding! I might have miscommunicated my need, so let me clarify.

The part about hiding the div, that part I'm ok with, but it's the step(s) before that I'm stuck.

Here is the scenario: I populate the list with a bit of code that looks like this:

quote:
JOIN
LEFT_OUTER SETTINGCODE IN VFILTER_FORLOCATION_DEV TO UNIQUE LOCTYPECODE IN VLOCATION AS J1
END
TABLE FILE VFILTER_FORLOCATION_DEV
PRINT DST.PILLAR
DST.MEASURENAME
DST.LOCDESCR
-*BY PILLAR NOPRINT
BY PILLARID
BY MEASURENAME NOPRINT
BY MEASUREID
BY LOCDESCR NOPRINT
BY LOCSHORTDESCR
ON TABLE SET HOLDLIST PRINTONLY
ON TABLE PCHOLD FORMAT XML
END


And with it, I have the "Add 'ALL' option" checked in the properties of the checkbox.

So I need to determine two things: 1) does the hold file return an empty result, in which case I must hide the checkbox, and 2) if the hold file returns nothing, find the checkbox marked 'ALL' and hide it also.

But how to grab the control before it's rendered to the page, determine if the result set is empty or not, and then hide the control (or a div governing the control), that's where I'm stuck.

Does this help clarify anymore? I don't know how to tell programatically if there are no results given from the XML at runtime, so that I can hide the checkboxlist if I need to.

Appreciate very much the help, too Smiler

Peter


WebFOCUS v. 7.6.10
___________________
Win2k3 Server
Intel Xeon 2.3Ghz/4Gb Ram Apache / IIS / SQL Srvr 2005
December 23, 2010, 01:48 PM
Tony A
Peter,

For your first question - 1) does the hold file return an empty result - I would be inclined to add a process to the window_onload function, after the UpdateData(); to check the length of the items within your SELECT control - e.g. document.getElementById("listbox1").options.length - if the length is 0 then you have no options loaded so it's safe to hide the combo and checkbox.

If you place both the combo and the checkbox within the same DIV then a only a single code line to hide them.

Edited as I forgot to mention that intercepting the control length before it's rendered would not be possible without creating your own AJAX retrieval and XML parsing routines - and as they already exist in ibirls3 why bother? You're probably better off waiting for the controls to load and then hide them if necessary.

T

This message has been edited. Last edited by: Tony A,



In FOCUS
since 1986
WebFOCUS Server 8.2.01M, thru 8.2.07 on Windows Svr 2008 R2  
WebFOCUS App Studio 8.2.06 standalone on Windows 10 
December 24, 2010, 01:17 PM
PeterV
Hi Tony! Yes, it would return an empty result set, so your idea might just be what I'm looking for. Thanks again so much, I'm going to test it out and see if I can get it working.

Blessings and have a wonderful Christmas/NewYears Smiler


WebFOCUS v. 7.6.10
___________________
Win2k3 Server
Intel Xeon 2.3Ghz/4Gb Ram Apache / IIS / SQL Srvr 2005