Hide buttons in HTML

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

LVL 17
MurpheyApplication ConsultantAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Randy PooleCommented:
<?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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Lee SavidgeCommented:
<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
GaryCommented:
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
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

MurpheyApplication ConsultantAuthor Commented:
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
Lee SavidgeCommented:
= sets a variable to the given value
== is a logical test to check for equality
0
GaryCommented:
Ermm I gave you the correct answer above, the accepted answer is wrong.
0
Lee SavidgeCommented:
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
GaryCommented:
Arghh, too much jquery, thought I had changed it.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
HTML

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.