views:

255

answers:

3

i have a href like this:

<a href="images/prevFeb-1.jpg" name="day-1" onclick="swap(this); return false;">
  <img src="images/thumbFeb-1.jpg" width="50" height="50" alt="" title="thumbFeb-1.jpg" />
</a>

when the user clicks on a thumbnail, the images get swap. i will like to get the href name upon on click. and i will explode("-",$hrefName) and like to get the value "1"

any ideas many thanks!

A: 

If you have the hyperlink name fixed then better use substring on the name of your link.

Ravia
the link is not seen, and i dont want the link to be seen in the browser, currently link works fine, i only want the name of the href? any ideas?
Menew
+1  A: 

Is this what you're looking for?

function swap(element) {
  var name = element.attributes.getNamedItem("name").value;
  var nameValue = name.split('-')[1];
  // do something with it...
}

More about getNamedItem() here: http://www.w3schools.com/DOM/met_nodemap_getnameditem.asp

Brad G.
well, here is my original js, so i am not sure if adding your suggestion might do the trick but i will give it a try! <script type="text/javascript"> function swap(image) { document.getElementById("main").src = image.href; } </script>
Menew
erm... you do know you can just do `var name= element.name`, right?
bobince
great, will try element.name; can i assign this to a php variable?
Menew
Well, you'd have to pass the `nameValue` in as the parameter to an AJAX request and have PHP read that into a variable from `$_GET`/`$_POST`, but yes.
bobince
A: 

here is my original swap js:

function swap(image) { document.getElementById("main").src = image.href; }

so all i want is to swap the images; and i also want to access the achor tag name value as well?

Menew