Syntax Problems with Function

S

Steve Bishop

I am trying to check for a fields value on load and hide certian
controls based on it's value. I am having trouble with the "else"
statement and the bracket placement. Help appreciated. Here is the code:
<HTML>
<HEAD>
<SCRIPT LANGUAGE="JavaScript">
function HideTable(){
var myform1 = document.form1
var myform2 = document.form2
if (myform1.txtName1.value == "Size Mix")
document.getElementById("tn3").style.visibility="hidden";
document.getElementById("but1").style.visibility="hidden";
document.getElementById("Table2").style.visibility="visible";
else
document.getElementById("tn3").style.visibility="visible";
document.getElementById("but1").style.visibility="visible";
document.getElementById("Table2").style.visibility="hidden";
}
</SCRIPT>
</HEAD>
<BODY onLoad="HideTable()">
 
E

ExGuardianReader

Steve said:
I am trying to check for a fields value on load and hide certian
controls based on it's value. I am having trouble with the "else"
statement and the bracket placement. Help appreciated. Here is the code:
<HTML>
<HEAD>
<SCRIPT LANGUAGE="JavaScript">
function HideTable(){
var myform1 = document.form1
var myform2 = document.form2
if (myform1.txtName1.value == "Size Mix")
document.getElementById("tn3").style.visibility="hidden";
document.getElementById("but1").style.visibility="hidden";
document.getElementById("Table2").style.visibility="visible";
else
document.getElementById("tn3").style.visibility="visible";
document.getElementById("but1").style.visibility="visible";
document.getElementById("Table2").style.visibility="hidden";
}
</SCRIPT>
</HEAD>
<BODY onLoad="HideTable()">

Jeesuz, don't you look at ANY documentation or ANY code before writing?

What do you think the {} marks are for???? They enclose code. Enclose
code between them that belongs in one *block*.
 
D

Douglas Crockford

Steve said:
I am trying to check for a fields value on load and hide certian
controls based on it's value. I am having trouble with the "else"
statement and the bracket placement. Help appreciated. Here is the code:
function HideTable(){
var myform1 = document.form1
var myform2 = document.form2
if (myform1.txtName1.value == "Size Mix")
document.getElementById("tn3").style.visibility="hidden";
document.getElementById("but1").style.visibility="hidden";
document.getElementById("Table2").style.visibility="visible";
else
document.getElementById("tn3").style.visibility="visible";
document.getElementById("but1").style.visibility="visible";
document.getElementById("Table2").style.visibility="hidden";
}

Use jslint to correct this: http://www.crockford.com/javascript/lint.html
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Members online

Forum statistics

Threads
473,770
Messages
2,569,583
Members
45,075
Latest member
MakersCBDBloodSupport

Latest Threads

Top