JavaScript: "missing ;" or "unexpected token JavaScript }" -


i'm trying debug simple code , kind of scratching head. i've copied code internet, checkboxs working radio button.

<input type="checkbox" name="priorityhigh" id="priorityhigh" onclick="if(this.checked){document.getelementbyid('prioritylow').checked=false;}"> vlacp short <input type="checkbox" name="prioritylow" id="prioritylow" onclick="if(this.checked){document.getelementbyid('priorityhigh').checked=false;}">vlacp long 

this above code works fine when i'm testing in simple new page.

but when incorporated code main code, if user select tagall, call function optioncheck() shown below.

function optioncheck(){      var div = document.createelement('div');     var option = document.getelementbyid("tagid_"+k ).value;      if(option == "tagall"){         div.innerhtml ='<input type="checkbox" name="priorityhigh" id="priorityhigh" onclick="if(this.checked){document.getelementbyid("prioritylow").checked=false;}"> vlacp short<input type="checkbox" name="prioritylow" id="prioritylow" onclick="if(this.checked) {document.getelementbyid("priorityhigh").checked=false;}">vlacp long';         document.getelementbyid('tag').appendchild(div);     }     if(option == "untagall"){         div.innerhtml ='stp fast:<input type="checkbox" name="stpfast_" value="stpfast" id = "stpfast_' + k + '"checked>&nbsp; slpp gaurd:<input type="checkbox" name="slppgaurd" value="slppgaurd" id = "slppgaurd_' + k + '" checked>';         document.getelementbyid('tag').appendchild(div);     }     if(option == "untagpvid"){         window.location = "http://google.com";     }  } 

now if run code complain "unexpected token javascript }", after debuging realized problem use of double quote , fixed shown below:

 div.innerhtml ='<input type="checkbox" name="priorityhigh" id="priorityhigh" onclick="if(this.checked){document.getelementbyid('prioritylow').checked=false;}"> vlacp short <input type="checkbox" name="prioritylow" id="prioritylow" onclick="if(this.checked) {document.getelementbyid('priorityhigh').checked=false;}">vlacp long'; 

now, facing weird error saying syntaxerror: missing; before statement on above line on coloumn 132.

you have 2 problems. first, remove "enter" after vlacp short. second, concatenate strings correctly (add escape character, backslash, needed):

// example 1 div.innerhtml ='<input type="checkbox" name="priorityhigh" id="priorityhigh" onclick="if(this.checked){document.getelementbyid(\'prioritylow\').checked=false;}"> vlacp short <input type="checkbox" name="prioritylow" id="prioritylow" onclick="if(this.checked) {document.getelementbyid(\'priorityhigh\').checked=false;}">vlacp long';  // example 2 div.innerhtml ='<input type="checkbox" name="priorityhigh" id="priorityhigh" onclick="if(this.checked){document.getelementbyid(\'prioritylow\').checked=false;}"> vlacp short'    + '<input type="checkbox" name="prioritylow" id="prioritylow" onclick="if(this.checked) {document.getelementbyid(\'priorityhigh\').checked=false;}">vlacp long'; 

Comments

Popular posts from this blog

how to insert data php javascript mysql with multiple array session 2 -

c++ - How to test/verify that zero-initialization takes place -

node.js - Webpack/TypeScript Raising Errors When node_modules is Excluded -