<script>$(document).ready(function() {
$('#offset').change(function(){
$('#casillaOffset').append('<fieldset><legend>Offset</legend><table>
<tr>
<tdid="Subtitulo"><divalign="left"id="Subtitulo">Densitometría:</div></td>
<tdid="Subtitulo"><divalign="left">
<inputtype="checkbox"name="densi"id="densi"/>
</div></td>
<td><divalign="left"id="Subtitulo2">PdeTinta:</div></td>
<td><divalign="left">
<inputtype="checkbox"name="p_tinta"id="p_tinta"/>
<inputname="cant_colores"type="number"id="cant_colores"min="0"max="99"size="2"maxlength="2"/>
</div></td>
<td></td>
<td></td>
<td></td>
</tr>
<tr>
<tdid="Subtitulo"><divalign="left">TirosR.Offset:</div></td>
<tdid="Subtitulo"><divalign="left">
<inputname="t_reales"type="text"id="t_reales"size="8"readonly="readonly"/>
</div></td>
<td><divalign="left"id="Subtitulo">TirosB.Offset:</div></td>
<td><divalign="left">
<inputname="tiros_totales"type="text"id="tiros_totales"value="0"size="8"readonly="readonly"/>
</div></td>
<tdid="formula"></td>
<td></td>
<td></td>
</tr>
<tr>
<td><divalign="left"id="Subtitulo">MaquinasOffset:</div></td>
<td><?php include("../select_list/lista_maquinas_offset.php");?>
</td>
<td>FechaDistribución:</td>
<td><inputname="fecha_offset"type="text"class="fecha_offset"id="fecha_offset"value="<?php echo date("d-m-Y");?>"size="10"readonly="readonly"/></td>
<td><aonclick="abreVentana()"href="#"id="ver">ver</a></td></tr>
</table>
</fieldset>')
});
})</script>
I am getting "Uncaught SyntaxError: Unexpected token <" in the following code. I get this error when I try to insert this code.
The php is not the problem, because I erased this an the problem even continues.
<script>$(document).ready(function() {
$('#offset').change(function(){
$('#casillaOffset').append('<fieldset><legend>Offset</legend><table>
<tr>
<tdid="Subtitulo"><divalign="left"id="Subtitulo">Densitometría:</div></td>
<tdid="Subtitulo"><divalign="left">
<inputtype="checkbox"name="densi"id="densi"/>
</div></td>
<td><divalign="left"id="Subtitulo2">PdeTinta:</div></td>
<td><divalign="left">
<inputtype="checkbox"name="p_tinta"id="p_tinta"/>
<inputname="cant_colores"type="number"id="cant_colores"min="0"max="99"size="2"maxlength="2"/>
</div></td>
<td></td>
<td></td>
<td></td>
</tr>
<tr>
<tdid="Subtitulo"><divalign="left">TirosR.Offset:</div></td>
<tdid="Subtitulo"><divalign="left">
<inputname="t_reales"type="text"id="t_reales"size="8"readonly="readonly"/>
</div></td>
<td><divalign="left"id="Subtitulo">TirosB.Offset:</div></td>
<td><divalign="left">
<inputname="tiros_totales"type="text"id="tiros_totales"value="0"size="8"readonly="readonly"/>
</div></td>
<tdid="formula"></td>
<td></td>
<td></td>
</tr>
<tr>
<td><divalign="left"id="Subtitulo">MaquinasOffset:</div></td>
<td><?php include("../select_list/lista_maquinas_offset.php");?>
</td>
<td>FechaDistribución:</td>
<td><inputname="fecha_offset"type="text"class="fecha_offset"id="fecha_offset"value="<?php echo date("d-m-Y");?>"size="10"readonly="readonly"/></td>
<td><aonclick="abreVentana()"href="#"id="ver">ver</a></td></tr>
</table>
</fieldset>')
});
})</script>
I am getting "Uncaught SyntaxError: Unexpected token <" in the following code. I get this error when I try to insert this code.
The php is not the problem, because I erased this an the problem even continues.
Share Improve this question edited Sep 13, 2013 at 16:43 user229044♦ 240k41 gold badges344 silver badges347 bronze badges asked Sep 13, 2013 at 16:32 Hector Chacon PerezHector Chacon Perez 451 gold badge4 silver badges11 bronze badges 2- That'll be the line-breaks in your to-be-inserted HTML. – Andy Commented Sep 13, 2013 at 16:33
- your string concatenation is not proper... line breaks are not allowed – Arun P Johny Commented Sep 13, 2013 at 16:34
2 Answers
Reset to default 3The reason it is not working is because javascript strings must be terminated before the next newline character.
If you wish to have a string which spans multiple lines, you may insert a backslash character '\' just before you terminate the line, like this:
$('#casillaOffset').append('<fieldset><legend>Offset</legend><table>\
<tr>\
<tdid="Subtitulo"><divalign="left"id="Subtitulo">Densitometría:</div></td>\
<tdid="Subtitulo"><divalign="left">');
or join multiple lines like this:
$('#casillaOffset').append('<fieldset><legend>Offset</legend><table>' +
'<tr>' +
'<tdid="Subtitulo"><divalign="left"id="Subtitulo">Densitometría:</div></td>' +
'<tdid="Subtitulo"><divalign="left">');
You're better off having that html in something like <div id="toAppend">html here</div>
and then pick it up with a jQuery selector targeted it at the html:
$(document).ready(function() {
$('#offset').change(function(){
$('#casillaOffset').append($('#toAppend').html());
});
});