Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Question about literals

42 views
Skip to first unread message

Mtek

unread,
May 17, 2008, 2:59:43 PM5/17/08
to
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[i], 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

VK

unread,
May 17, 2008, 3:26:35 PM5/17/08
to
On May 17, 10:59 pm, Mtek <m...@mtekusa.com> wrote:
> 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.


0 new messages