Reputation: 45
<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.
Upvotes: 3
Views: 6293
Reputation: 88
The 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">');
Upvotes: 3
Reputation: 63570
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());
});
});
Upvotes: 1