In the application we are currently building, we need to write positioning
code on-the-fly, based upon the screen offset of the element in the AS/400
application which drives the Web app. The 400, like DOS, uses memory-mapped
display, two bytes per character (one char byte and one attribute byte). We
can get the screen offset allright, and I've written a javascript which does
the math to convert the offset into row/col (i.e. left, top) values for the
element's Style declaration. The problem is, when I go to document.write the
HTML, the write stops at the first semicolon delimiter in the Style
declaration, regardless of the fact that it is enclosed in a string. Here is
the HTML source for this element:
<td height="020" width="27px" onfocus="tC(this)" onblur="tC(this)"
style="text-align:left;">
<span id="spanID0162" class="redUBL">
<script>setPos("0162");</script>
<script>pS("Bad","left");</script>
<script>endPos();</script>
</span>
</td>
setPos() and endPos() call the functions which calculate and document.write
the opening <div> tag, with the positioning Style declaration, and the end
</div> tag. The objective is something like this:
<td height="020" width="27px" onfocus="tC(this)" onblur="tC(this)"
style="text-align:left;">
<span id="spanID0162" class="redUBL">
<div style="position:absolute; left:10px; top:41px;">
<script>pS("Bad","left");</script>
</div>
</span>
</td>
What we get instead for the <div> declaration is
<div style="position:absolute">
where the document.write is clearly stopping at the first semicolon.
I have tried using character entities, UTF hex values, Unicode, with and
without quotes, enclosing in CDATA (it's an XHTML doctype), escapes, you
name it (see script, below, which shows some but not all of the variations
attempted), with no success. So, my question is, can what we want to do be
done? If so, how? If not, is there another approach which anyone can suggest
that we might take which would offer a greater chance of success, given that
the positioning must be done on the fly? Thanks.
function setPos(offset)
{
var rowPos = Math.floor(offset/80);
var topVal = (rowPos * 20) + 1 // Row 3 (rowPos = 2) top pixel is at pixel
41 and goes to pixel 60
var colPos = (offset % 80);
var leftVal = ((colPos -1) * 9) + 1; // Column 2 begins at pixel 10 and goes
to pixel 18
//document.write("<div style='position:absolute" + "U+003B" + " left:" +
leftVal + "U+003B" + " top:" + topVal + "U+003B" + "'>");
//document.write("<div style='position:absolute" + ";" + " left:" +
leftVal + ";" + " top:" + topVal + ";" + "'>");
//document.write("<div style='position:absolute" + "0x3B" + " left:" +
leftVal + "0x3B" + " top:" + topVal + "0x3B" + "'>");
//document.write("<div style='position:absolute" + "\;" + " left:" + leftVal
+ "\;" + " top:" + topVal + "\;" + "'>");
//document.write("<div style='position:absolute" + 0x3B + " left:" + leftVal
+ 0x3B + " top:" + topVal + 0x3B + "'>");
//document.write("<div style='position:absolute'>");
//<![CDATA[
document.write('<div style="position:absolute; left:' + leftVal + '; top:' +
topVal + ';">');
//]]>
} // function setPos
Cheers,
Scott