Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

document.write syntax issue

Posted on 2006-11-16
6
Medium Priority
?
298 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 100 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
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 

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 400 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

Whether you've completed a degree in computer sciences or you're a self-taught programmer, writing your first lines of code in the real world is always a challenge. Here are some of the most common pitfalls for new programmers.
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…
Progress

715 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