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 11-20-2010, 04:39 AM   PM User | #1
es696
New to the CF scene

 
Join Date: Nov 2010
Posts: 4
Thanks: 1
Thanked 0 Times in 0 Posts
es696 is an unknown quantity at this point
Really having trouble here

OK i really hope someone can help me because this has put a complete halt to what I'm doing right now.

i have various images in a 12x12 grid with names such as x1y1, x2y2, ect

I need to check what x1y1's image SRC is. I have been trying stuff like this:

var xpos = 1
var ypos = 1
var IMAGENAME = "x" + xpos + "y" + ypos

blah = ('document.' + IMAGENAME + '.src')

if (blah == "something.gif") {
do what i want
}


Just doesn't work, nor has the 80 other things I've tried lol.

Can anyone help me out?

Last edited by es696; 11-20-2010 at 04:56 AM..
es696 is offline   Reply With Quote
Old 11-20-2010, 05:02 AM   PM User | #2
gizmo1650
Regular Coder

 
Join Date: Apr 2010
Posts: 163
Thanks: 3
Thanked 25 Times in 25 Posts
gizmo1650 is on a distinguished road
How is your grid made?
try blah = document.getElementByName(IMAGENAME).src
gizmo1650 is offline   Reply With Quote
Old 11-20-2010, 05:13 AM   PM User | #3
es696
New to the CF scene

 
Join Date: Nov 2010
Posts: 4
Thanks: 1
Thanked 0 Times in 0 Posts
es696 is an unknown quantity at this point
the grid is just tons of images with x and y names. no IDs

k i have this, with your idea included:

var xpos = 1
var ypos = 1

function moveup() {
var test1 = "x" + xpos + "y" + ypos
document.form.textbox1.value = document.getElementByName(test1).src


the two lines above^ dont work and code below (dont pay attention to it) fails to execute.:


if(xpos == 10) {
} else {
eval('document.x' + xpos + 'y' + ypos + '.src="tiles/grass.jpg"');
xpos=(xpos+1)
var pos = "x" + xpos + "y" + ypos
eval('document.x' + xpos + 'y' + ypos + '.src="sprites/up.gif"');
}}

Last edited by es696; 11-20-2010 at 05:25 AM..
es696 is offline   Reply With Quote
Old 11-20-2010, 07:14 AM   PM User | #4
Old Pedant
Supreme Master coder!

 
Old Pedant's Avatar
 
Join Date: Feb 2009
Posts: 23,542
Thanks: 62
Thanked 4,054 Times in 4,023 Posts
Old Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to all
He is asking, did you do <img name="x7y11"> or <img id="x7y11">????

For name=
Code:
var IMAGENAME = "x" + xpos + "y" + ypos
var imageSrc = document.images[IMAGENAME].src;
or
document.images[IMAGENAME].src = "something.gif";
But that's a bit old fashioned.

Would be better to use id's instead of names, and then:
Code:
var IMAGENAME = "x" + xpos + "y" + ypos
var imageSrc = document.getElementById(IMAGENAME).src;
or
document.getElementById(IMAGENAME).src = "something.gif";
__________________
An optimist sees the glass as half full.
A pessimist sees the glass as half empty.
A realist drinks it no matter how much there is.
Old Pedant is offline   Reply With Quote
Old 11-20-2010, 06:10 PM   PM User | #5
es696
New to the CF scene

 
Join Date: Nov 2010
Posts: 4
Thanks: 1
Thanked 0 Times in 0 Posts
es696 is an unknown quantity at this point
OK thanks for the help. So far so good. I do have one more question if you dont mind =)

document.images[IMAGENAME].src

^ That worked but it gives me the full path to the SRC. Is there a way to just return the value alone?

Thanks for the help guys i really appreciate it!
es696 is offline   Reply With Quote
Old 11-20-2010, 08:51 PM   PM User | #6
Old Pedant
Supreme Master coder!

 
Old Pedant's Avatar
 
Join Date: Feb 2009
Posts: 23,542
Thanks: 62
Thanked 4,054 Times in 4,023 Posts
Old Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to all
You would need to then strip off the path. You can't change what HTML thinks the ".src" is.

Not hard:
Code:
var isrc = document.images[IMAGENAME].src
isrc = isrc.substring( isrc.lastIndexOf("/") + 1 );
That is, just get everything *past* the last / in the src.
__________________
An optimist sees the glass as half full.
A pessimist sees the glass as half empty.
A realist drinks it no matter how much there is.
Old Pedant is offline   Reply With Quote
Users who have thanked Old Pedant for this post:
es696 (11-22-2010)
Old 11-22-2010, 12:42 AM   PM User | #7
es696
New to the CF scene

 
Join Date: Nov 2010
Posts: 4
Thanks: 1
Thanked 0 Times in 0 Posts
es696 is an unknown quantity at this point
thank you sir!
es696 is offline   Reply With Quote
Reply

Bookmarks

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 06:00 AM.


Advertisement
Log in to turn off these ads.