?
Solved

Hide buttons in HTML

Posted on 2014-08-19
8
Medium Priority
?
237 Views
Last Modified: 2014-08-19
Hi Experts,

I need help with the following HTML problem:

There is an existing HTML page, containing a simple table and several buttons.
I like to hide the buttons depending on the table contents.
Button1 must be visible if <TD id=S2> contains "ABC"
Button2 must be visible if <TD id=S1> is not empty or blank.

I thought it was easy (see example) but it doesn't work :-(

<?xml version="1.0" encoding="iso-8859-1"?>
<html>
    <table>
      <tr>
        <td>
          <b>Customer</b>
        </td>
        <td id="S1"></td>
      </tr>
      <tr>
        <td>
          <b>Status</b>
        </td>
        <td id="S2">ABC</td>
      </tr>
    </table>
	<!-- something more -->
    <table>
        <td>
			<button id="B2" onclick="location.href='MyPageABC'">Click ABC</button> 
		</td>
        <td>
			<button id="B1" onclick="location.href='MyPageXYZ'">Click XYZ</button>
		</td>
      </tr>
    </table>
		<script>
			if (document.getElementById("S2").value != "ABC") document.getElementById("B2").style.visibility = "hidden";
			if (document.getElementById("S1").value = "") document.getElementById("B1").style.visibility = "hidden";
		</script>
  </body>
</html>

Open in new window

0
Comment
Question by:theo kouwenhoven
8 Comments
 
LVL 21

Accepted Solution

by:
Randy Poole earned 2000 total points
ID: 40270214
<?xml version="1.0" encoding="iso-8859-1"?>
<html>
<head>
		<script language='Javascript'>
                        function setbuttons(){
			if (document.getElementById("S2").innerHTML!= "ABC") document.getElementById("B2").style.visibility = "hidden";
			if (document.getElementById("S1").innerHTML= "") document.getElementById("B1").style.visibility = "hidden";
                        }
		</script>
</head>
<body onLoad='setbuttons();'>
    <table>
      <tr>
        <td>
          <b>Customer</b>
        </td>
        <td id="S1"></td>
      </tr>
      <tr>
        <td>
          <b>Status</b>
        </td>
        <td id="S2">ABC</td>
      </tr>
    </table>
	<!-- something more -->
    <table>
        <td>
			<button id="B2" onclick="location.href='MyPageABC'">Click ABC</button> 
		</td>
        <td>
			<button id="B1" onclick="location.href='MyPageXYZ'">Click XYZ</button>
		</td>
      </tr>
    </table>

  </body>
</html>

Open in new window

0
 
LVL 25

Expert Comment

by:Lee Savidge
ID: 40270228
<script>
          if(document.getElementById('S2').innerHTML != 'ABC') document.getElementById('B2').style.visibility = 'hidden';
          if (document.getElementById('S1').innerHTML != '') document.getElementById('B1').style.visibility = 'hidden';
</script>

Open in new window

0
 
LVL 58

Expert Comment

by:Gary
ID: 40270266
In JS = is to set a value, == is to compare a value
<script>
if (document.getElementById("S2").innerText != "ABC") document.getElementById("B2").style.visibility = "hidden";
if (document.getElementById("S1").innerText == "") document.getElementById("B1").style.visibility = "hidden";
</script>

Open in new window

0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 16

Author Comment

by:theo kouwenhoven
ID: 40270306
Hi Randy,

Thanks for the quick response, i had to replace the:
   if (document.getElementById("S1").innerHTML= "")
-by-
   if (document.getElementById("S1").innerHTML== "")

Can you tell me the dif. between = and == ?


Thanks again !!!!

Murph
0
 
LVL 25

Expert Comment

by:Lee Savidge
ID: 40270309
= sets a variable to the given value
== is a logical test to check for equality
0
 
LVL 58

Expert Comment

by:Gary
ID: 40270312
Ermm I gave you the correct answer above, the accepted answer is wrong.
0
 
LVL 25

Expert Comment

by:Lee Savidge
ID: 40270344
I'd agree that the accepted answer isn't quite right but your answer isn't either:

You put:

if (document.getElementById("S2").innerText != "ABC") document.getElementById("B2").style.visibility = "hidden";
if (document.getElementById("S1").innerText == "") document.getElementById("B1").style.visibility = "hidden";

Open in new window


It should be:

          if (document.getElementById('S2').innerHTML != 'ABC') document.getElementById('B2').style.visibility = 'hidden';
          if (document.getElementById('S1').innerHTML != '') document.getElementById('B1').style.visibility = 'hidden';

Open in new window

0
 
LVL 58

Expert Comment

by:Gary
ID: 40270425
Arghh, too much jquery, thought I had changed it.
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
In this tutorial viewers will learn how to embed custom externally-hosted Google Fonts using the Google Font API in CSS Go to the Google Fonts website at google.com/fonts: Browse or search based on font properties or name to find a suitable font for…
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).
Suggested Courses

839 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question