Today I was trying to make the innerHTML of a DIV change to a FORM, but I keep getting the following error Uncaught SyntaxError: Unexpected token ILLEGAL
. I've modified the code to say changed
and it works fine, but if I try to change it to the following code it gives me that error.
document.getElementById(div).innerHTML = '<form method="post" action="all.php?f=mu">
<input name="afterurl" type="hidden" value="<?php $url ?>" />
<input name="preurl" type="hidden" value="" />
<input name="newurl" type="text" value="" />
</form>';
Any idea how I can get it to work?
Today I was trying to make the innerHTML of a DIV change to a FORM, but I keep getting the following error Uncaught SyntaxError: Unexpected token ILLEGAL
. I've modified the code to say changed
and it works fine, but if I try to change it to the following code it gives me that error.
document.getElementById(div).innerHTML = '<form method="post" action="all.php?f=mu">
<input name="afterurl" type="hidden" value="<?php $url ?>" />
<input name="preurl" type="hidden" value="" />
<input name="newurl" type="text" value="" />
</form>';
Any idea how I can get it to work?
Share Improve this question edited Oct 8, 2011 at 8:51 JohnP 50k13 gold badges112 silver badges141 bronze badges asked Oct 8, 2011 at 8:25 givawaygivaway 235 bronze badges1 Answer
Reset to default 10You can't have text span multiple lines like that in JS. Use string concatenation or put it into one line
document.getElementById(div).innerHTML = '<form method="post" action="all.php?f=mu">' +
'<input name="afterurl" type="hidden" value="<?php $url ?>" />' +
'<input name="preurl" type="hidden" value="" />' +
'<input name="newurl" type="text" value="" />' +
'</form>';