html - Generating checkbox using javascript -


I have written this javascript code to generate the check box:

  ques = document .getElementById ("question"); Var q = ques.appendChild (document.createElement ("ol")); Q.appendChild (document.createTextNode (allQuestions [0] .Question); Var list = ques.appendChild (document.createElement ("ul")); (Var i = 0; i & lt; 4; i ++) for {var option = list.appendChild (document.createElement ("input")); Option.type = "checkbox"; List.appendChild (document.createTextNode (allQuestions [0] .choices [i])); List.appendChild (document.createElement ("br"); }  

The result is in the following output:

Enter image details here

and generated HTML is:

  & lt; Input type = "checkbox" & gt; David Cameron & lt; Br> & Lt; Input type = "checkbox" & gt; Gordon Brown & lt; Br> & Lt; Input type = "checkbox" & gt; Winston Churchill & lt; Br> & Lt; Input type = "checkbox" & gt; Tony Blair & lt; Br> & Lt; / Ul & gt;  

The output looks ok but I think the result is not correct HTML. It should be:

  & lt; Input type = "checkbox" & gt; David Cameron & lt; Br>  

May be both are similar and may be different I'm not sure. Can anyone tell me the difference? Please suggest improvement even in my code, if there is a better way to generate a checkbox.

Edit: My question is not about white spaces. HTML code generates the checkbox and the text in front of it is not connected. I think that they should be bound to a certain extent because the check box is for text, is there any possible method related to the text in the checkboxes?

Common way to relate this text's check box to label < / Code> and for the attribute are used:

  & lt; Input type = "checkbox" id = "foo" value = "David Cameron" & gt; & Lt; Label for = "foo" & gt; David Cameron & lt; / Label & gt; Note the  

value attribute, which should be full of your text or anything, like id db of text.


Comments

Popular posts from this blog

java - Can't add JTree to JPanel of a JInternalFrame -

javascript - data.match(var) not working it seems -

javascript - How can I pause a jQuery .each() loop, while waiting for user input? -