Solved

document.write syntax issue

Posted on 2006-11-16
6
291 Views
Last Modified: 2010-04-16
I have a line of code inside a .js file that I have been messing with regarding the single and doulbe quotes and have not been able to resolve.  The idea here is to let the user click on the image and then a small window opens up.

Here is the code:

document.write('<a href=javascript:window.open("picture1details.asp",PageDescription,scrollbars="yes",menubar="no",toolbar="no",status="no",top="10",left="10",height="500",width="500",resizable="yes");return(false)><img src="picts/15242.jpg"  NAME="but" WIDTH="160" HEIGHT="83" BORDER="0" ALT="click to view details">/a>');

The click event occurs in the .asp that references the .js but the window does not open.  And, yes, the picture1details.asp is the right url.

Thanks.
0
Comment
Question by:dklauk
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
6 Comments
 
LVL 43

Expert Comment

by:TimCottee
ID: 17954813
Hi dklauk,

document.write('<a href=javascript:window.open("picture1details.asp",PageDescription,"scrollbars=yes,menubar=no,toolbar=no,status=no,top=10,left=10,height=500,width=500,resizable=yes");return(false)><img src="picts/15242.jpg"  NAME="but" WIDTH="160" HEIGHT="83" BORDER="0" ALT="click to view details">/a>');


Tim Cottee
0
 
LVL 5

Assisted Solution

by:kumar_jac
kumar_jac earned 25 total points
ID: 17954866

Hi,
   That is document.write or Response.write anyway my suggestion is split that as a java script fuction and pass the argument to that fucation then
code is clean
no repeted item
easy to maintain

Ex :

document.write('<a href="javascript:OpenDetails(argument);" > <img src="picts/15242.jpg"  NAME="but" WIDTH="160" HEIGHT="83" BORDER="0" ALT="click to view details"> </a>');

function OpenDetails(argument)
{
window.open("picture1details.asp",PageDescription,scrollbars="yes",menubar="no",toolbar="no",status="no",top="10",left="10",height="500",width="500",resizable="yes");
return(false);
}

Note :
also you
write /a> instead of </a> plz fix that too
0
 
LVL 43

Expert Comment

by:TimCottee
ID: 17954907
dklauk,

Actually, there are a few other things that need sorting as well as the incorrect parameters to the window.open call.

document.write('<a href="" onclick="javascript:window.open(&#39;picture1details.asp&#39;,&#39;PageDescription&#39;,&#39;scrollbars=yes,menubar=no,toolbar=no,status=no,top=10,left=10,height=500,width=500,resizable=yes&#39;);return(false);"><img src="picts/15242.jpg"  NAME="but" WIDTH="160" HEIGHT="83" BORDER="0" ALT="click to view details"></a>');

This solves the problem of the various quotes by using the encoded values for them. They will be rendered correctly to the page even though it does make it a little less readable perhaps.



Tim
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:dklauk
ID: 17954966
Tim Cottee's last suggestion worked; kumar_jac's didn't--although I prefer this coding approach.

kumar_jac: any idea why your solution did not work?  
0
 
LVL 43

Accepted Solution

by:
TimCottee earned 100 total points
ID: 17954978
dklauk,

The reason is that the window.open function has incorrectly specified parameters, these were copied down from your original. You could do exactly the same with my method as well:
document.write('<a href="javascript:OpenDetails(argument);" > <img src="picts/15242.jpg"  NAME="but" WIDTH="160" HEIGHT="83" BORDER="0" ALT="click to view details"> </a>');

function OpenDetails(argument)
{
window.open("picture1details.asp","PageDescription","scrollbars=yes,menubar=no,toolbar=no,status=no,top=10,left=10,height=500,width=500,resizable=yes");
return(false);
}

Tim
0
 

Author Comment

by:dklauk
ID: 17955258
TimCottee, your last suggestion does not work either.  However, it will work if I remove the 'argument' from the javascript:OpenDetails(argument) code and remove it from the .asp function OpenDetails(argument).  But, when I then run the .asp it does open a new window but then displays the text,  "false", in the parent browser window.


??
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
If you’re thinking to yourself “That description sounds a lot like two people doing the work that one could accomplish,” you’re not alone.
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…

710 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question