Question about literals

M

Mtek

Hi,

We have a script where we are changing the innerHTML value. To do
that, we have concatenated a string, and then we set it.

In one of those string is some javascript. The javascript MUST exist
under the control which it is realted to. The code below works fine
if in regular HTML. But, we cannot get it to work when we make it
part of the string like this. We're using some XML, but that is not
the problem, as it works fine when in regular HTML. It is the
middle section that is in question:

str = str + '<table cellspacing="0" cellpadding="0"
style="border-collapse: collapse">';
str = str + ' <tr>';
str = str + ' <td><span class=star>* </span><input
type="text" name="RegDate" id="RegDate" readonly="1" VALUE=' +
getElementTextNS("", "reg_date", r, 0) + '></td>';
str = str + ' <td>&nbsp;<img src="../images/admin2/
calendar_img.gif" id="f_trigger_c" style="cursor: pointer; border: 1px
solid red;" title="Reg Date" onmouseover="this.style.background=\'red
\';" onmouseout="this.style.background=\'\'"></td>';
str = str + ' </tr>';
str = str + '</table><br>';


-- This part is not working.

str = str + '<script>';
str = str + ' Calendar.setup({';
str = str + ' inputField : "RegDate", ';
str = str + ' ifFormat : "%B %e, %Y",';
str = str + ' button : "f_trigger_c",';
str = str + ' align : "Tl",';
str = str + ' singleClick : true });';
str = str + '<\/script>';



str = str + '<BR><CENTER><span class=labels><B>Reg Date</
CENTER></TD>';
str = str + '</TR>';
str = str + '<TR><TD colspan=2><img src=\'../images/rsvp/
spacer.gif\' height=10></TD></TR>';
str = str + '</table>';
str = str + '</CENTER>';
document.getElementById('details').innerHTML = str;


We get no errors, nothing at all. It just does not work when we click
the button. Any suggestions would help us out a lot!

Thanks!

John
 
V

VK

We have a script where we are changing the innerHTML value. To do
that, we have concatenated a string, and then we set it.

In one of those string is some javascript. The javascript MUST exist
under the control which it is realted to.


No it doesn't: stop this railed Ruby crap propaganda. And if you
really insisting on raw source dumping into document, at least change
concatenations by String concat() method. You'll be amazed by the
productivity growth on some browsers, I promise.

The code below works fine
if in regular HTML. But, we cannot get it to work when we make it
part of the string like this.

Right, script added by script as a raw source patch is not executed.
This is why btw many Ruby-type projects are falling apart as soon as
they get a bit more complex. A minimum code demonstrating your
problem:

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN">
<html>
<head>
<meta http-equiv="Content-type"
content="text/html; charset=iso-8859-1">
<title>Demo</title>
<script type="text/javascript">
function init() {
var demo = document.getElementById('demo');
demo.innerHTML = ''.concat(
'<script>window.alert("Will not work")<\/script>'
);
}

function releaseContextAndInit() {
window.setTimeout('init()',10);
}
window.onload = releaseContextAndInit;
</script>
</head>
<body>
<p id="demo">&nbsp;</p>
</body>
</html>

If you are on a really severe time limit to re-write a descent
program, try to search at Ruby forums:
http://www.ruby-forum.com/search?query=javascript&submit=Search
They are continuously looking for fixes for exactly such situations so
maybe someone came with a fix.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,001
Messages
2,570,249
Members
46,846
Latest member
BettinaOsw

Latest Threads

Top