Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Can you put <%=xyz%> in a javascript block?

Status
Not open for further replies.

Lunytic

Technical User
Nov 20, 2003
21
0
0
US
I'm trying to make a complicated rollover situation where by mousingover an image in the top left cell of a 2x2 table, text appears in the bottom left cell (this works), and an image appears in the top right cell (I've also got this to work). This is where it get complicated. Now I want the user to be able to mouseover the image that popped up (one of 3 depending on where they are in the first image), and have text appear in the bottom right cell.

Does ASP work well with Javascripting?

I've tried numerous ways, so now I'm just asking if what I'm doing is even possible. So, can I do this:

<SCRIPT LANGUAGE=&quot;JAVASCRIPT&quot;>
if (document.images) {
image1 = new Image
image2 = new Image
image3 = new Image

image1.src = &quot;<%=image3%>&quot;
image2.src = &quot;<%=image2%>&quot;
image3.src = &quot;<%=image1%>&quot;

}
</SCRIPT>


??? Am I looking at this all wrong? Should I be trying something else? Am I stupid for putting <%=image1%> in a scriptblock?

Thank you.
 
Does ASP work well with Javascripting?

yes, there is nothing wrong with that and is common practice

_____________________________________________________________________
onpnt2.gif
[sub]
Hakuna matata!!
[/sub]
 
Okay, thats a relief, at least I'm on the rigth path. Then did I specify something wrong? Here is a sample of my work(trucated for readability, there are 2 more image maps in the <% %>). Because right now the image to the right doesn't work, but there are no overt errors. (Just a little exclemation mark in the bottom left of the browswer).


<%
image3 = &quot;<map name=&quot;&quot;FPMap3&quot;&quot;>&quot;
image3 = image3 & &quot;<area href=&quot;&quot;cutarea.jpg&quot;&quot; shape=&quot;&quot;rect&quot;&quot; coords=&quot;&quot;121, 181, 202, 275&quot;&quot;&quot;
image3 = image3 & &quot;mouseover=&quot;&quot;document.getElementById('123').innerHTML='&quot;&test3&&quot;'&quot;&quot;>&quot;
image3 = image3 & &quot;<area href=&quot;&quot;cutarea.jpg&quot;&quot; shape=&quot;&quot;rect&quot;&quot; coords=&quot;&quot;222, 53, 265, 101&quot;&quot;&quot;
image3 = image3 & &quot;mouseover=&quot;&quot;document.getElementById('123').innerHTML='&quot;&test3&&quot;'&quot;&quot;>&quot;
image3 = image3 & &quot;<area href=&quot;&quot;cutarea.jpg&quot;&quot; shape=&quot;&quot;rect&quot;&quot; coords=&quot;&quot;0, 74, 101, 190&quot;&quot;&quot;
image3 = image3 & &quot;mouseover=&quot;&quot;document.getElementById('123').innerHTML='&quot;&test3&&quot;'&quot;&quot;>&quot;
image3 = image3 & &quot;</map>&quot;
image3 = image3 & &quot;<img src=&quot;&quot;pyramids.jpg&quot;&quot; width=&quot;&quot;300&quot;&quot; height=&quot;&quot;300&quot;&quot; usemap=&quot;&quot;#FPMap3&quot;&quot;>&quot;
%>



<SCRIPT LANGUAGE=&quot;JAVASCRIPT&quot;>
if (document.images) {
image1 = new Image
image2 = new Image
image3 = new Image

image1.src = &quot;<%=image3%>&quot;
image2.src = &quot;<%=image2%>&quot;
image3.src = &quot;<%=image1%>&quot;

}
</SCRIPT>
 
Using the code above, the asp for image3 should be...

<%
image3 = &quot;myImageName.jpg&quot;
%>


What you have gives this on the client side...

image3.src = &quot;<area href=&quot;&quot;cutarea.jpg&quot;&quot; shape=&quot;&quot;rect&quot;&quot; coords=&quot;&quot;121, 181, 202, 275&quot;&quot;&quot; mouseover=&quot;&quot;document.getElementById('123').innerHTML='&quot;&test3&&quot;'&quot;&quot;>&quot;
&quot;<area href=&quot;&quot;cutarea.jpg&quot;&quot; shape=&quot;&quot;rect&quot;&quot; coords=&quot;&quot;222, &quot;mouseover=&quot;&quot;document.getElementById('123').innerHTML='&quot;&test3&&quot;'&quot;&quot;>&quot;53, 265, 101&quot;&quot;&quot;

you get the idea -

in javascript you should say

image3.src = &quot;myPicture.jpg&quot;
the source cannot have the maps, areas or mouseovers...

Programming today is a race between software engineers striving to build better and bigger idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning. - Rick Cook (No, I'm not Rick)

fart.gif
 
How do I image map the images that pop up then? It does work with the =&quot;pyramids.jpg&quot; for example, but I can't figure out how to map &quot;pyramids.jpg&quot;, or at least how to map it, &quot;careful.jpg&quot; and &quot;acey8212.jpg&quot; so there is a different map used for whichever of the three images is currently up.

On the bright side, I better undertsand how <%=xyz%> works. :p
 
When working with asp in JavaScript/HTML, you need to imagine what the code needs to look like when the server sends it to the client (ie - the HTML your code outputs).

If you need a map for an image..

<map name=&quot;img3Map&quot;>
<area shape=rect coords=&quot;0,0,100,100&quot; href=&quot;page1.htm&quot;>
<area shape=rect coords=&quot;100,100,150,150&quot; href=&quot;page2.htm&quot;>
</map>

<img src=&quot;somePic.jpg&quot; usemap=&quot;#img3Map&quot;>

Is the straight HTML...
This is what you'd get is you response.write your &quot;image3&quot; in your asp

<body>
<%=image3%>
</body>

note that you don't need any javascript...


Programming today is a race between software engineers striving to build better and bigger idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning. - Rick Cook (No, I'm not Rick)

fart.gif
 
<img src=&quot;somePic.jpg&quot; usemap=&quot;#img3Map&quot;>

Is the straight HTML...


What I want to do though, is to replace the &quot;somePic.jpg&quot;
with &quot;pic1&quot; &quot;#img1Map&quot;
with &quot;pic2&quot; &quot;#img2Map&quot;
with &quot;pic3&quot; &quot;#img3Map&quot;


Here's the mouseover code that works on the top-left image.

<area shape=&quot;polygon&quot;
coords=&quot;295, 296, 298, 191, 280, 206, 239, 244, 198, 278, 186, 296&quot;
onmouseover=&quot;document.getElementById('goodcutid').innerHTML='<%=test3%>',
document.imagename.src=image3.src&quot;>

I appologize for either not communicating well enough, or not getting what you mean. If you want, I can post the link to the page that I'm working on, instead of giving snipits here. (I wast trying to keep the cluter down).

Thank you for your help, and patience with me.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top