[RESOLVED] Javascript: Assign innerHTML to DIV
Hi,
As the title suggests, I'm trying to dynamically assign the innerHTML of a DIV tag, but I can't get it to work. I've escaped the characters correctly, but I only get garbage. Here's some code so that you can see what I'm talking about.
VB Code:
<SCRIPT language="JavaScript">
function ProcessMediumSelection()
{
document.getElementById('divExpectedReturnDate2').innerHTML = '<script>DateInput(\\'ReturnDate\\', true, \\'DD-MON-YYYY\\')</script>';
}
Is it getting mixed up by the <script> tag in the HTML I'm trying to assign? When the page is rendered, fragments of the code above is shown at the top. :confused: Anyone know how I can do this?
Re: Javascript: Assign innerHTML to DIV
< = <
> = >
& = &
" = "
These are the basic replacements to be made.
Re: Javascript: Assign innerHTML to DIV
You need to split the script end tag into two parts. Some HTML processors recognize it as the end of your actual script.
Code:
document.getElementById('divExpectedReturnDate2').innerHTML =
'<sc'+'ript>DateInput(\'ReturnDate\', true, \'DD-MON-YYYY\')</scr'+'ipt>';
However, I'm not sure if this means the browser will actually execute the new code. Besides, why would you WANT such confusing code?