0

I'm getting an error on the if statement - it can't make the compare ('unexpected indentifier') but I can't figure out why. I'm guessing it has to do with the fact that "table" is not a string object.. This code is implemented inside a C code so you should Ignor The "\n" and the " signs

              "function postRow(i,table){\n"

                "var desc=document.getElementsByName('description'+table);\n"
                "var inter=document.getElementsByName('logInterval'+table);\n"  
                
                "if( table.equals('AN') || table.equals('OW') ){\n"
                  "var mu=document.getElementsByName('mul'+table);\n"
                  "var di=document.getElementsByName('div'+table);\n"
                  "var off=document.getElementsByName('offset'+table);\n"
               "$.post('',{func:'saveTable'+table,\n"
                            "index:i,\n"
                            "description:desc[i].value,\n"
                            "logInterval:inter[i].value,\n"
                            "mul:mu[i].value,\n"
                            "div:di[i].value,\n"
                            "offset:off[i].value,\n"  
                        "});"
                "}\n"
                
                "else if (table.equals('DG') ){\n"
                  "var count=document.getElementsByName('counterDG');\n"
                  "$.post('',{func:'saveTable'+table,\n"
                            "index:i,\n"
                            "description:desc[i].value,\n"
                            "logInterval:inter[i].value,\n"
                            "counter:count[i].value,\n"
                       "});\n"                 
                "}\n"

                "setTimeout(updateTable(table),1000);"     
                "}\n"

Calling the function:

onclick=postRow(i,"DG");

3
  • 1
    Where is the error ? Commented Mar 12, 2015 at 10:24
  • Sorry, I will edit the post :-) Commented Mar 12, 2015 at 10:24
  • 1
    Why dont you actually remove all the \n and " just for us to easily read it? This makes it harder to read. What does tables.equals() do? Commented Mar 12, 2015 at 10:29

2 Answers 2

1

Javascript strings don't have an .equals() method. Use the === operator:

if (table === 'AN' || table === 'OW')
Sign up to request clarification or add additional context in comments.

1 Comment

I tried it at the beginning and it didn't work.. I'll try again
0

Instead of using table.equals('AN'), use table == ('AN').

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.