View Full Version : conditional href

02-16-2010, 04:05 AM
Does anyone know how i could do this as a condiftional statement? I want to set a variable based on the image selected and then pass that variable as a session variable and open a page. All I want is a way to pass a value to a variable when the user clicks one of the image maps. I don't want to use a form with a submit button. Is there any other way to accomplish this?

Thanks Art

<map name="Map" id="Map">
<area shape="rect" coords="732,24,817,47" href="#" />
<area shape="rect" coords="822,24,919,48" href="#" />
<area shape="rect" coords="924,24,1012,48" href="#" />

02-16-2010, 06:21 AM
With what you have, you cannot do this with just php. PHP is pure server side, and you're href is a hash target, so thats all client side. With AJAX you could do this.
However, if you change you're href to include an identifier for the particular image (ie: <area shape="rect" coords="w,x,y,z" href="page.php?image=uniqueVal" />), then you can detect this with the $_GET superglobal on the page.php.

02-16-2010, 01:04 PM
If i understand correctly, i would use an intermediate page and use the value in image to detect which link was clicked? how would this be possible in ajax?


02-16-2010, 01:46 PM
Correct. The intermediate page could be this page with conditions though, it doesn't technically have to be a new script.
Ajax would simply use the same page to take care of this behind the scenes. You would instead use an onclick event to pass some identifiable information to the page, get the result and do what you need to do with it. W3Schools has a pretty straight forward AJAX tutorial: http://www.w3schools.com/Ajax/Default.Asp
Questions relating to AJAX would go under the javascript subforum for AJAX and Design. You'll need to ensure that the return result is either plain text or well formed xml.

02-17-2010, 11:59 AM
thanks it worked like a charm