Go Back   CodingForums.com > :: Client side development > JavaScript programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 03-09-2012, 06:01 PM   PM User | #1
jack_wookie
New to the CF scene

 
Join Date: Mar 2012
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
jack_wookie is an unknown quantity at this point
XY Coords and so much more

I have a project where I need to be able to control four things onClick. I have a set of 12 arrows (3 colors, 4 directions) and I need to specify the XY coordinate of the arrow tip and I need to call the arrow by color and direction (instead of by src). Is this something that I can do with a 2d array?

My Java looks like this:

function ixycoord(i,x,y) {

document.images["baseimage"].src = i;

if (document.getElementById)
{document.getElementById("baseimage").style.top = y;
document.getElementById("baseimage").style.left = x} else

if (document.layers)
{document.baseimage.top = y; document.baseimage.left = x} else
{document.all.baseimage.style.top = y; document.all.baseimage.style.left = x}
}


And the HTML looks like this:

<div id="baseimage">
<img id="baseimage" src="/arrowred.png">
</div>

<p>This is a the <a href="#n" onClick="ixycoord('whiteup.png',49,57)"> aorta</a>. This is the <a href="#n" onClick="ixycoord('blueleft.png',145,144)"> ventricle </a> and this is the <a href="#n" onClick="ixycoord('redright.png',220,230)">pericardium</a>. </p>


I have to be able to make it *NOT* have the the image source in the onClick. Thanks in advance for any help you can give me!
jack_wookie is offline   Reply With Quote
Old 03-09-2012, 07:22 PM   PM User | #2
swiper
New to the CF scene

 
Join Date: Feb 2012
Location: New York, NY
Posts: 8
Thanks: 1
Thanked 0 Times in 0 Posts
swiper is an unknown quantity at this point
did you notice the id for the div and the img is the same??
id is supposed to be unique
swiper is offline   Reply With Quote
Old 03-09-2012, 07:26 PM   PM User | #3
swiper
New to the CF scene

 
Join Date: Feb 2012
Location: New York, NY
Posts: 8
Thanks: 1
Thanked 0 Times in 0 Posts
swiper is an unknown quantity at this point
change your div id to

<div id="baseimagediv">

and you're all set
swiper is offline   Reply With Quote
Old 03-10-2012, 04:19 AM   PM User | #4
jmrker
Senior Coder

 
jmrker's Avatar
 
Join Date: Aug 2006
Location: FL
Posts: 2,797
Thanks: 30
Thanked 462 Times in 456 Posts
jmrker will become famous soon enough
@jack_wookie

Could you provide a link to the images so we could see the final product in action?
jmrker is offline   Reply With Quote
Old 03-10-2012, 07:50 AM   PM User | #5
Philip M
Supreme Master coder!

 
Philip M's Avatar
 
Join Date: Jun 2002
Location: London, England
Posts: 17,101
Thanks: 197
Thanked 2,421 Times in 2,399 Posts
Philip M has a spectacular aura aboutPhilip M has a spectacular aura aboutPhilip M has a spectacular aura about
document.layers relates to Netscape4, which is one with Nineveh and Tyre.

Quote:
Originally Posted by jack_wookie View Post
My Java looks like this:
Java and Javascript are entirely different programming languages, in spite of the confusingly similar names. Rather like Austria and Australia!
__________________

All the code given in this post has been tested and is intended to address the question asked.
Unless stated otherwise it is not just a demonstration.

Last edited by Philip M; 03-10-2012 at 07:53 AM..
Philip M is offline   Reply With Quote
Old 03-10-2012, 08:34 AM   PM User | #6
webdev1958
Banned

 
Join Date: Apr 2011
Posts: 656
Thanks: 14
Thanked 69 Times in 69 Posts
webdev1958 can only hope to improve
That's fairly straight forward, but need to see the images so we can see the location of the arrow tip.
webdev1958 is offline   Reply With Quote
Old 03-12-2012, 09:07 PM   PM User | #7
jack_wookie
New to the CF scene

 
Join Date: Mar 2012
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
jack_wookie is an unknown quantity at this point
I apparently wasn't clear enough. All of the arrows point to the correct spot. The code works just fine, everything does exactly as it is supposed to. The alternate arrows are stored in a folder and are successfully called and put in the correct place based on the XY coordinates. The code is fine.

My problem is:

My boss thinks it is too cumbersome to have to write the image name each time. That is he thinks, IXYcoords ("image.png", 345, 454) etc. is too cumbersome. Instead he wants four points (color, direction, x, y).

So let's say we have 12 arrows labeled by (3) color and (4) direction.
whiteup.png, bluedown.png, etc.

I need to have the arrows called by (white, down, 384, 472). Can I do this with an array of some sort?
jack_wookie is offline   Reply With Quote
Old 03-12-2012, 10:47 PM   PM User | #8
jmrker
Senior Coder

 
jmrker's Avatar
 
Join Date: Aug 2006
Location: FL
Posts: 2,797
Thanks: 30
Thanked 462 Times in 456 Posts
jmrker will become famous soon enough
Lightbulb

Not sure I understand the need of an array...
Add to JS
Code:
function pic(iColor, iDirection) { return iColor+iDirection+'.png'; }
Change HTML
Code:
<p>
 This is a the <a href="#n" onClick="ixycoord(pic('white','up'),49,57)"> aorta</a>.
 This is the <a href="#n" onClick="ixycoord(pic('blue','left'),145,144)"> ventricle </a> and
 this is the <a href="#n" onClick="ixycoord(pic('red','right'),220,230)">pericardium</a>. 
</p>
jmrker is offline   Reply With Quote
Reply

Bookmarks

Tags
array, arrows, onclick, xy coordinates

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 09:46 AM.


Advertisement
Log in to turn off these ads.