Solved

document.write syntax issue

Posted on 2006-11-16
6
286 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
  • 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
ScreenConnect 6.0 Free Trial

Want empowering updates? You're in the right place! Discover new features in ScreenConnect 6.0, based on partner feedback, to keep you business operating smoothly and optimally (the way it should be). Explore all of the extras and enhancements for yourself!

 

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

Problems using Powershell and Active Directory?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

Question has a verified solution.

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

This article is meant to give a basic understanding of how to use R Sweave as a way to merge LaTeX and R code seamlessly into one presentable document.
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…

831 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