PDA

View Full Version : Help regarding innerHTML



mike
12-19-2005, 04:17 AM
Hi,
I used innerHTML like the following.
<script>
td_id.innerHTML="<script>functionname(param);</script>";
</script>

But this is not working. Can anyone help to solve this.

Regards,
Karthik.

jscheuer1
12-19-2005, 07:04 AM
Assuming that:

td_id

is a valid object that supports an innerHTML object (if it is, it would have needed to have been defined as such elsewhere and before this code is executed), the slash (/) should be escaped (\/) to contribute to the page's potential to pass validation. More importantly, you need to break up the </script> tag in the string literal. Otherwise, the script parser thinks it is the end of the script:


td_id.innerHTML="<script>functionname(param);<"+"\/"+"script>";

mike
12-19-2005, 08:04 AM
Thanx John, it's working fine

mwinter
12-19-2005, 11:35 AM
td_id.innerHTML="<script>functionname(param);<"+"\/"+"script>";[/]That's rather excessive:


td_id.innerHTML = '<script type="text/javascript">functionname(param);<\/script>';Notice that all that is necessary is a simple slash.

Mike