Jump to content

[SOLVED] $x++ is working half-ish


deadlyp99

Recommended Posts

Well I've posted a lot of questions lately, and I try to give back by helping others.

But today I have another question

 

I have a image map with coordinates, and it also updates a <span> with the #'s I assign via php.

 

$x and $y both have an initial value of 0.

 

<area shape="poly" coords="304,112,267,131,305,152,340,132" alt="1,0" onmouseover="document.getElementById("x").innerHTML="'.$Xarray[$x].'";document.getElementById("y").innerHTML="'.$Yarray[$y].'";" href="?x='.$Xarray[$x].'&y='.$Yarray[$y].'" />
<area shape="poly" coords="304,112,267,131,305,152,340,132" alt="1,0" onmouseover="document.getElementById("x").innerHTML="'.$Xarray[$x++].'";document.getElementById("y").innerHTML="'.$Yarray[$y].'";" href="?x='.$Xarray[$x++].'&y='.$Yarray[$y].'" />

 

Now when I print_r($Xarray), I get the correct stuff (36, 37, 38, etc). In addition, the link of the image on the second area does  increase like it should, to 37. However the javascript mouse over does not increment.

 

So when I look at the source code on the page I see:

 

<area shape="poly" coords="267,91,230,111,269,131,303,112"  alt="0,0" onmouseover="document.getElementById('x').innerHTML='36';document.getElementById('y').innerHTML='-4';" href="?x=36&y=-4" />
<area shape="poly" coords="304,112,267,131,305,152,340,132" alt="1,0" onmouseover="document.getElementById('x').innerHTML='36';document.getElementById('y').innerHTML="-4';" href="?x=37&y=-4" />

 

Notice the "36" and the "37" on the bottom area? That's my  problem.

I'm not sure what's causing it, but help would be greatly appreaciated.

 

Thanks for your time.

 

If it becomes needed, I'll fill more area map fields to see if it is an ongoing problem. But I really don't want to have to go through mass amounts of fixing line by line with the same repetive change so I started with just these 2 boxes.

Link to comment
Share on other sites

Well now that I have thought of it I made more then one error in my logic, but it doesnt bring me to a solution.

 

In my head I want my Javascript, followed by the link to print out like so:

JS 36 -4, Link 36 -4
JS 37 -4, Link 37 -4
JS 38 -4, Link 38 -4
JS 39 -4, Link 39 -4

 

But I just realized this error how following the logic it should be printed

$Xarray = (36, 37, 38, 39, 40, 41, 42);
$Yarray = (-4, -5, -6, -7, -8, -9, -10);
JS 36 -4, Link 36 -4
JS 37 -4, Link 38 -4
JS 39 -4, Link 40 -4
JS 41 -4, Link 42 -4

 

Since the first item in teh array is 36, the first $x++ should bring it to 37, and the second $x++ 38 correct?

I can fix the second by removing the "++", but the code isnt operating how i'm thinking it should I guess

 

To be as clear as I can, I want the javascript event, and the href, to have the same value per line, so that the link matches the javascript coordinate being displayed.

Link to comment
Share on other sites

I'm an idiot lol. I was completly over-doing it

 

<area shape="poly" coords="304,112,267,131,305,152,340,132" alt="1,0" onmouseover="document.getElementById("x").innerHTML="'.$Xarray[0].'";document.getElementById("y").innerHTML="'.$Yarray[0].'";" href="?x='.$Xarray[0].'&y='.$Yarray[0].'" />
<area shape="poly" coords="304,112,267,131,305,152,340,132" alt="1,0" onmouseover="document.getElementById("x").innerHTML="'.$Xarray[1].'";document.getElementById("y").innerHTML="'.$Yarray[0].'";" href="?x='.$Xarray[1].'&y='.$Yarray[0].'" />

 

So simple -.-

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.