Reputation: 129
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?
Upvotes: 0
Views: 89
Reputation: 2708
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...
Upvotes: 1
Reputation: 3323
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.
Upvotes: 0
Reputation: 969
Unescaped single quotes inside your code surrounded by single quotes.
Upvotes: 1
Reputation: 167162
$('#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!
$('#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>');
Upvotes: 2