PDA

View Full Version : Puzzle: Losing quotes (") around attributes in Rendered HTML using document.write(var


MattyUK
10-30-2002, 10:49 AM
Hi

I am losing double quote marks (") around attributes in HTML rendered through document.write(variable).

Some survice, some don't and I can't work out why. I could really use a hand.

This Javascript code:
<SCRIPT language="JavaScript">
<!--
var pwcode='TESTITEMCODE';
var pwtitle='TITLE';
var pwprice='PRICE';
var pwfile='iknowimbroken.jpg';
var pwdescription='A text description to go here.';
var pwcols='<OPTION value="'+'COLOUR1'+'">'+'COLOUR1'+'</OPTION>';
var pwsizes='<OPTION value="'+'SIZE1'+'">'+'SIZE1'+'</OPTION>';

var pagestring='<FORM name="'+pwcode+'" method="post" action=""><TABLE width="90%" border="0" cellspacing="2" cellpadding="0" align="center"><TR><TD rowspan="4" width="150" align="center" valign="middle"><IMG src="productimages/'+pwfile+'"></TD><TD align="left" valign="top"><P><B>'+pwtitle+'</B></P></TD><TD align="right" valign="top"> <P><A onClick="parent.cr(\''+pwcode+'\')" href="#">'+pwcode+' - ADD TO CART</A></P></TD><TD align="center" valign="top" class="border"><P>£'+pwprice+'</P></TD></TR><TR><TD align="left" valign="top" colspan="2" rowspan="3"><P>'+pwdescription+'</P></TD><TD align="center" valign="top" class="border"><P> Colours<BR><SELECT name="Colour">'+pwcols+'</SELECT></P></TD></TR><TR><TD align="center" valign="top" class="border"><P>Sizes<BR><SELECT name="Size">'+pwsizes+'</SELECT></P></TD></TR><TR><TD align="center" valign="top">&nbsp;</TD></TR></TABLE></FORM>';
document.write(pagestring);
//-->
</SCRIPT>

Is part of a larger chunk of code and the variables are pulled from a data array. However the pwstring variable is what interests us. See the first line has double quotes around every tag attribute. Yet the HTML code it rendereds is this:

<FORM name=TESTITEMCODE action="" method=post><TABLE cellspacing=2 cellpadding=0
width="90%" align=center border=0>
<TBODY>
<TR>
<TD valign=center align=middle width=150 rowspan=4><IMG
src="productimages/iknowimbroken.jpg"></TD>
<TD valign=top align=left>
<P><B>TITLE</B></P></TD>
<TD valign=top align=right>
<P><A onClick="parent.cr('TESTITEMCODE')" href="#">TESTITEMCODE - ADD TO
CART</A></P></TD>
<TD class=border valign=top align=middle>
<P>£PRICE</P></TD></TR>
<TR>
<TD valign=top align=left colspan=2 rowspan=3>
<P>A text description to go here.</P></TD>
<TD class=border valign=top align=middle>
<P>Colours<BR><SELECT name=Colour><OPTION value=COLOUR1
selected>COLOUR1</OPTION></SELECT></P></TD></TR>
<TR>
<TD class=border valign=top align=middle>
<P>Sizes<BR><SELECT name=Size><OPTION value=SIZE1
selected>SIZE1</OPTION></SELECT></P></TD></TR>
<TR>
<TD valign=top align=middle>&nbsp;</TD></TR></TBODY></TABLE></FORM>

Where have the (") double quotes around the attributes gone?

Why have some survived and not others?

How can we make them appear at will (i.e. around all tag attribute values)?

I am using Microsofts web developer accessories to view the rendered HTML source code as the default method of veiwing didn't work for me (it showed only the downloaded source code with the Javascript).

http://www.microsoft.com/windows/ie/previous/webaccess/default.asp
http://www.microsoft.com/windows/ie/previous/webaccess/webdevaccess.asp

I have already tried escaping all double quotes (\") to no avail.

Bear in mind that usually the rendered HTML would appear within another document and thus have the HTML tags and document type set.

This is a real puzzle and I could really use a hand. Please help if you can.


Thanks in advance.

MattyUK

Garadon
10-30-2002, 12:30 PM
one thoery could be that the microsoft program shows u code in an edited form, indications of this.

1. Ur dould quotes gone.
2. ur attributes are shuffled around
example:
Ur String:
<TABLE width="90%" border="0" cellspacing="2" cellpadding="0" align="center">
Result Code:
<TABLE cellspacing=2 cellpadding=0 width="90%" align=center border=0>

Notice of the attributes is shuffled

3. its a microsoft program, it is probably made to show code in a
certain standard

MattyUK
10-30-2002, 12:38 PM
Well spotted. Thank you.

Now that that is ruled out it leaves me with bigger problems. But I guess that is another post. Cheers again.