2

I need to add a checkbox in a html table I know the usual method like

    <td>  
        <input type="checkbox" name ="chk1" />  
    </td>

My current code is

string html=""; 
html += "<table>";
html += "<tr><th>" + "A" + "</th><th>" + "B" + "</th><th>" + "C" + </th></tr>";
html += "<tr><td>" + "0" + "</td><td>" + "1" + "</td><td>" + "2" + </td></td>+"<input type="checkbox" name ="chk1" /> "  +</td>  </tr>"; 
html += "</table>";

but this gives an error

2
  • 2
    Change the double Quotes " to Single ' for type and name values... it will work Commented Jan 23, 2013 at 5:22
  • 4
    I like SO's syntax highlighting, it clearly points out to you: where the error is! Commented Jan 23, 2013 at 5:23

3 Answers 3

3

You have missed some quotes

please use this code

string html=""; 
html += "<table>";
html += "<tr><th>" + "A" + "</th><th>" + "B" + "</th><th>" + "C" + "</th></tr>";
html += "<tr><td>" + "0" + "</td><td>" + "1" + "</td><td>" + "2" + "</td></td>"+"<input type='checkbox' name ='chk1' /> "  +"</td>  </tr>"; 
html += "</table>";
Sign up to request clarification or add additional context in comments.

1 Comment

hey dude, we are not asp.net developers, just copied his code and edited :)
2

It appears that you're missing a quote, also you can get rid of some of the quotes (and rows):

string html=""; 
html += "<table>";
html += "<tr><th>A</th><th>B</th><th>C</th></tr>";
html += "<tr><td>0</td><td>1</td><td>2</td></td><input type=\"checkbox\" name =\"chk1\" /></td></tr>"; 
html += "</table>";

Comments

1

No need of concatenations, just put single quotes outside as given in the example below:

string html = ''; 
html += '<table>';
html += '<tr><th>A</th><th>A</th><th>C</th></tr>';
html += '<tr><td>0</td><td>1</td><td>2</td></td><input type="checkbox" name ="chk1"  /></td></tr>'; 
html += '</table>';

6 Comments

@krshekhar: We all just copied the OP's code and helping him out to close the quotes properly. The error you mentioned is an html structure error not a code error.
@krshekhar: If you are agree then undo all the down votes you did. Thanks.
but I am not able to up-vote because it(SO) is not letting me to do so unless you edit your answer.
I don't say to give up vote, but you have an option of undo just move your mouse on down arrow (then you will see an option of undo in a tool tip) and click it again.
Even I am unable to do so. It is giving me the same message.
|

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.