Solved

document.write syntax issue

Posted on 2006-11-16
6
287 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
Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 

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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

This is an explanation of a simple data model to help parse a JSON feed
Computer science students often experience many of the same frustrations when going through their engineering courses. This article presents seven tips I found useful when completing a bachelors and masters degree in computing which I believe may he…

840 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