Helpful Information
 
 
Category: JavaScript Development
mail(); & javascript & urlencode...please help!!!

Before I ask my question please use the following URL's as reference b/c this may sound a bit confusing:

http://www.digitalbait.com/product_info.php?cPath=1_7&products_id=35&

http://www.digitalbait.com/Outward/redirect.php?url=http://www.commission-junction.com%2Ftrack%2Ftrack.dll%3FAID%3D1195162%26PID%3D602255%26TYPE%3DPN%26URL%3Dhttp%253A%252F%2 52Fwww%252Evanns%252Ecom%252Fjmp%252Edna%253Fref%253Dcj%2526sku%253D580214895

The first URL is the products page and the second URL is the page of the product on an external site with a top frame linking back to my site. I have a button in the top frame that mail the URL (everything after ?url=) to a designated address using the mail(); function.

When the button on the top frame is clicked a new window opens notifying the user that the URL was sent. The way I originally had it written was to have a new browser window open with <target="_blank"> but I wanted to use javascript instead so I could control the size of the popup.

Without javascript the full URL was sent just fine but now that I implemented the javascript only part of the URL is being sent. urlencode is supposed to take care of this problem (which it does without javascript). Here is the original code and also the current code:

Original code:


<html>
<head>
<title>Thanks for using DigitalBait</title>
</head>
<?php
$qs = "?url=" . urlencode($url);
$URL = "broken_link.php" . $qs;
?>
<form method="post" action="<? echo($URL); ?>" target="_blank">
...rest of page...
<input type="image" name="submit" src="/images/frame/submit_link.gif" border="0" vspace="2" hspace="5">


Current code:


<html>
<head>
<title>Thanks for using DigitalBait</title>
</head>
<SCRIPT LANGUAGE="JavaScript">
function popUp(url) {
sealWin=window.open(url,"win",'toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=0,resizable=1,width=300,height=75 ');
self.name = "mainWin"; }
</SCRIPT>
<?php
$qs = "?url=" . urlencode($url);
$URL = "broken_link.php" . $qs;
?>
<form method="post" action="javascript:popUp('<? echo($URL); ?>')">
...rest of page...
<input type="image" name="submit" src="/images/frame/submit_link.gif" border="0" vspace="2" hspace="5">


The popUp window displays the following:


<html>
<body bgcolor="#cc6600">
<font face="verdana" size="2" color="white">

<?php
$to = "me@myaddress.com";
$subj = "Broken Link Report";
$body = $url;

$success = mail ($to, $subj, $body);
if ($success) {
echo ("The problem link was sent and we will get it fixed as soon as possible. Thank you for your cooperation.");
} else {
echo ("Error sending mail. Please resubmit link.");
}
?>
</font>
<br>
<div align="right"><FORM><font face="verdana" size="1" color="white">Close Window:&nbsp;<INPUT TYPE='BUTTON' VALUE='x' onClick='window.close()'></FORM></div>
</body>
</html>

What is it about the javascript that wont let urlencode do its job? I'm pulling my hair out over this one... Thanks in advance.

I guess yoy don't want to be using post to submit to a javascript function. Try something like this:

<form>
...rest of page...
<input type="image" name="submit" src="/images/frame/submit_link.gif" border="0" vspace="2" hspace="5" onClick="popUp(<? echo($URL); ?>)">
</form>

ie. use the onClick of the image to call the jscript. I may have missed some ' or " ;)

John

JohnB,
Thanks a lot, that did the trick. I'm still trying to understand why but I guess it doesn't matter now that it is working.










privacy (GDPR)