locked
Javascript syntax error? RRS feed

  • Question

  • Javascript

    function Submit1() {


        var x = document.getElementById("OTWOpt1");
        var y = x.options[x.selectedIndex].value;
        alert(y)

         If y = 1
      x.options[x.selectedIndex].text = "Wrong"
     else y = 2
      x.options[x.selectedIndex].text = "Right"

    }

    It doesn't work.  What syntax have I screwed up?


    Excel Worker Bee

    Wednesday, July 25, 2012 7:57 PM

Answers

  • Hello,

    Try to check following code:

    function Submit1() {
        var x = document.getElementById("OTWOpt1");
        var y = x.options[x.selectedIndex].value;
        alert(y);
    
         if (y == 1)
    	x.options[x.selectedIndex].text = "Wrong"
         else if (y == 2)
    	x.options[x.selectedIndex].text = "Right";
    }


    Microsoft CRM Freelancer

    My blog (english)
    Мой блог (русскоязычный)
    Follow Andriy on Twitter

    Wednesday, July 25, 2012 8:14 PM
    Moderator

All replies

  • Hello,

    Try to check following code:

    function Submit1() {
        var x = document.getElementById("OTWOpt1");
        var y = x.options[x.selectedIndex].value;
        alert(y);
    
         if (y == 1)
    	x.options[x.selectedIndex].text = "Wrong"
         else if (y == 2)
    	x.options[x.selectedIndex].text = "Right";
    }


    Microsoft CRM Freelancer

    My blog (english)
    Мой блог (русскоязычный)
    Follow Andriy on Twitter

    Wednesday, July 25, 2012 8:14 PM
    Moderator
  • Well that is just freaky.  I tried single and double = and didn't work either way.  I opened in FF and whammo worked with double.  Then saved and tried again in IE and it worked there too.     GRRRRR. 

    THANKS!!!!!!


    Excel Worker Bee

    Wednesday, July 25, 2012 8:25 PM