Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Strange Page Behavior with escaped quotes

Status
Not open for further replies.

Moebius01

Programmer
Joined
Oct 27, 2000
Messages
309
Location
US
Ok, this one has me baffled. I have a page for a video rental home delivery service to allow customers to browse the movies. There's a button to allow switching between VHS and DVD (simply calls a seperate page to change a session variable and return). The code to display the button is part of a display block as follows:
<CODE>
$platsel = $_SESSION[platsel];
if ($platsel < 1) {
$_SESSION[platsel] = 1;
$platsel = 1;
}
if ($platsel == 1) { $platname = &quot;DVD&quot;; $otherplat = &quot;Switch To VHS&quot;; }
if ($platsel == 2) { $platname = &quot;VHS&quot;; $otherplat = &quot;Switch To DVD&quot;; }


$header_block .=&quot; <td align=\&quot;center\&quot;><div style=\&quot;PADDING-RIGHT: 5px; PADDING-LEFT: 5px; PADDING-BOTTOM: 5px; PADDING-TOP: 0px\&quot;><font color=990000><input type=\&quot;button\&quot; value=\&quot;$otherplat\&quot; onClick=window.location=\&quot;demoswitchplat.php\&quot;></div></td>\n&quot;;
</CODE>

As far as I can tell, all seems happy there. However, the first time the page is called I see a syntax error, and upon looking at the source output to the browser, I see this:

<td align=&quot;center&quot;><div style=&quot;PADDING-RIGHT: 5px; PADDING-LEFT: 5px; PADDING-BOTTOM: 5px; PADDING-TOP: 0px&quot;><font color=990000><input type=&quot;button&quot; value=&quot;Switch To VHS&quot; onClick=&quot;window.location=&quot;&quot;demoswitchplat.php&quot;></div></td>

Note the way the quotes around the onClick are messed up. Refreshing the page fixes the problem:

<td align=&quot;center&quot;><div style=&quot;PADDING-RIGHT: 5px; PADDING-LEFT: 5px; PADDING-BOTTOM: 5px; PADDING-TOP: 0px&quot;><font color=990000><input type=&quot;button&quot; value=&quot;Switch To VHS&quot; onClick=window.location=&quot;demoswitchplat.php&quot;></div></td>

I'm assuming this has something to do with the session, but I can't for the life of me figure out why it doesn't work the first time when there is no session variable yet.



 
That's pretty much the bulk of the code for the button. The first chunk determines the current selection and creates the variables, the second part puts them into the HTML block. The quotes that I'm referring to are the escaped quotes in the $header_block statement. The kicker is in the output to browser on the first round. It places quotes where I didn't put them. On a refresh it works fine. Note the odd quote placement when the source is viewed.

onClick=&quot;window.location=&quot;&quot;demoswitchplat.php&quot;

The code is written to output it as

onClick=window.location=&quot;demoswitchplat.php&quot;

which it does properly on a refresh.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top