0

When i use this line of code row is getting added in table

$('#preq > tbody:last').append('<tr><td>Added here</td></tr>');

but when i use it for this it is not working

$('#preq > tbody:last').append('<tr><td><input title="Enter Kind Of work new" readonly="readonly" onclick="if(this.value!=''){this.value='';opendrop();}else{opendrop();}" id="other_work5" name="other_work5" type="text" size="30" onclick="opendrop()"  <?php if (isset($errors)) { echo 'value="'.htmlentities(@$_POST['other_workn']).'"'; } ?>></td><td><input name="client_name5" type="text" id="client_name5" size="40"/></td><td><input name="firm_name5" type="text" id="firm_name5" size="40"/></td></tr>');

where is the mistake?

3
  • why you have 2 onclick handlers for input in your code? Commented Jan 4, 2013 at 8:50
  • and it's better to use some IDE or editor which will highlight your errors, to prevent such simple cases Commented Jan 4, 2013 at 8:59
  • actually i am new to coding ,so can you suggest any such good editor,because in my editor it didn't show me this error Commented Jan 4, 2013 at 9:46

4 Answers 4

2

Unescaped string:

$('#preq > tbody:last').append('<tr><td><input title="Enter Kind Of work new" readonly="readonly" onclick="if(this.value!='')
--------------------------------------------^ {this.value='';opendrop();}else{opendrop();}" id="other_work5"
------------^
name="other_work5" type="text" size="30" onclick="opendrop()" <?php if (isset($errors)) { echo 'value="'.htmlentities(@$_POST['other_workn']).'"'; } ?>></td><td><input name="client_name5" type="text" id="client_name5" size="40"/></td><td><input name="firm_name5" type="text" id="firm_name5" size="40"/></td></tr>');

Just escape them using \' and you are good!

Working one:

$('#preq > tbody:last').append('<tr><td><input title="Enter Kind Of work new" readonly="readonly" onclick="if(this.value!=\'\'){this.value=\'\';opendrop();}else{opendrop();}" id="other_work5" name="other_work5" type="text" size="30" onclick="opendrop()" <?php if (isset($errors)) { echo 'value="'.htmlentities(@$_POST['other_workn']).'"'; } ?>></td><td><input name="client_name5" type="text" id="client_name5" size="40"/></td><td><input name="firm_name5" type="text" id="firm_name5" size="40"/></td></tr>');

Sign up to request clarification or add additional context in comments.

2 Comments

Introducing another programming language layer for something so mudane is like exterminating ants with nuclear warheads. This will work, but makes everything unneccessarily complicated. It also is a perfect rip-off of the code of MrXenotype.
@MartinHohenberg I answered this before him! FYIP!
1

You need to escape your single quotes. Try this:

$('#preq > tbody:last').append('' +
  '<tr>' +
    '<td>' +
      '<input title="Enter Kind Of work new" readonly="readonly" ' +
        'onclick="if(this.value!=\'\'){this.value=\'\';opendrop();}else{opendrop();}" id="other_work5" name="other_work5" type="text" size="30" ' +
        'onclick="opendrop()"  <?php if (isset($errors)) { echo 'value="'.htmlentities(@$_POST['other_workn']).'"'; } ?>>' +
    '</td>' +
    '<td>' +
      '<input name="client_name5" type="text" id="client_name5" size="40"/>' +
    '</td>' +
    '<td>' +
      '<input name="firm_name5" type="text" id="firm_name5" size="40"/>' +
    '</td>' +
  '</tr>'
);

Please also note that the php will be executed before the html is appended since PHP is server side...

Comments

1

Unescaped single quotes inside your code surrounded by single quotes.

Comments

0

The first single quote (') in

"if(this.value!='')

closes the string opened with

append('

Escape all single quotes in the string you want to append.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.