Syntax Problems with Function

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Steve Bishop

    Syntax Problems with Function

    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="JavaS cript">
    function HideTable(){
    var myform1 = document.form1
    var myform2 = document.form2
    if (myform1.txtNam e1.value == "Size Mix")
    document.getEle mentById("tn3") .style.visibili ty="hidden";
    document.getEle mentById("but1" ).style.visibil ity="hidden";
    document.getEle mentById("Table 2").style.visib ility="visible" ;
    else
    document.getEle mentById("tn3") .style.visibili ty="visible";
    document.getEle mentById("but1" ).style.visibil ity="visible";
    document.getEle mentById("Table 2").style.visib ility="hidden";
    }
    </SCRIPT>
    </HEAD>
    <BODY onLoad="HideTab le()">



    *** Sent via Developersdex http://www.developersdex.com ***
    Don't just participate in USENET...get rewarded for it!
  • ExGuardianReader

    #2
    Re: Syntax Problems with Function

    Steve Bishop wrote:[color=blue]
    > 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="JavaS cript">
    > function HideTable(){
    > var myform1 = document.form1
    > var myform2 = document.form2
    > if (myform1.txtNam e1.value == "Size Mix")
    > document.getEle mentById("tn3") .style.visibili ty="hidden";
    > document.getEle mentById("but1" ).style.visibil ity="hidden";
    > document.getEle mentById("Table 2").style.visib ility="visible" ;
    > else
    > document.getEle mentById("tn3") .style.visibili ty="visible";
    > document.getEle mentById("but1" ).style.visibil ity="visible";
    > document.getEle mentById("Table 2").style.visib ility="hidden";
    > }
    > </SCRIPT>
    > </HEAD>
    > <BODY onLoad="HideTab le()">[/color]

    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*.

    Comment

    • Douglas Crockford

      #3
      Re: Syntax Problems with Function

      Steve Bishop wrote:[color=blue]
      > 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:[/color]
      [color=blue]
      > function HideTable(){
      > var myform1 = document.form1
      > var myform2 = document.form2
      > if (myform1.txtNam e1.value == "Size Mix")
      > document.getEle mentById("tn3") .style.visibili ty="hidden";
      > document.getEle mentById("but1" ).style.visibil ity="hidden";
      > document.getEle mentById("Table 2").style.visib ility="visible" ;
      > else
      > document.getEle mentById("tn3") .style.visibili ty="visible";
      > document.getEle mentById("but1" ).style.visibil ity="visible";
      > document.getEle mentById("Table 2").style.visib ility="hidden";
      > }[/color]

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

      Comment

      Working...