What's wrong with this script?

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

    What's wrong with this script?

    I need a button to change text everytime a person clicks it. It should
    switch back and forth from "Request" to "Nevermind. " For some reason, this
    won't work at all. Does anyone see why it doesn't work?


    function changeButton(bu ttonId)
    {
    if (document.getEl ementById)
    {
    var button=document .getElementById (buttonId);
    if (button)
    {
    if (button.childNo des[0])
    {
    if (button.childNo des[0].nodeValue=="Re quest")
    {
    button.childNod es[0].nodeValue="Nev ermind";
    }
    else
    {
    button.childNod es[0].nodeValue="Req uest";
    }
    }
    else if (button.value)
    {
    if (button.value== "Request")
    {
    button.value="N evermind";
    }
    else
    }
    button.value="R equest";
    }
    }
    else //if (button.innerHT ML)
    {
    button.innerHTM L="Nevermind2 ";
    }
    }
    }
    }
  • Brian

    #2
    Re: What's wrong with this script?

    I guess this would be it:
    [color=blue]
    > else
    > }[/color]

    I spent 30 minutes trying to figure out why this script wouldn't work.
    GAH!

    Comment

    • Douglas Crockford

      #3
      Re: What's wrong with this script?

      > I need a button to change text everytime a person clicks it. It should[color=blue]
      > switch back and forth from "Request" to "Nevermind. " For some reason, this
      > won't work at all. Does anyone see why it doesn't work?
      >
      >
      > function changeButton(bu ttonId)
      > {
      > if (document.getEl ementById)
      > {
      > var button=document .getElementById (buttonId);
      > if (button)
      > {
      > if (button.childNo des[0])
      > {
      > if (button.childNo des[0].nodeValue=="Re quest")
      > {
      > button.childNod es[0].nodeValue="Nev ermind";
      > }
      > else
      > {
      > button.childNod es[0].nodeValue="Req uest";
      > }
      > }
      > else if (button.value)
      > {
      > if (button.value== "Request")
      > {
      > button.value="N evermind";
      > }
      > else
      > }
      > button.value="R equest";
      > }
      > }
      > else //if (button.innerHT ML)
      > {
      > button.innerHTM L="Nevermind2 ";
      > }
      > }
      > }
      > }[/color]

      (26) : error at character 9: Expected '{' and instead saw '}'.

      JSLINT can be very helpful in spotting errors like this.


      Comment

      Working...