views:

37

answers:

2

hopefully someone can help me. i want to get a thumbnail id value when an onclick event happens, but no luck, any ideas? thanks

<a href="test.ca/images/image-1.jpg?id=1"; onclick="swap(this); getVa(); return false;">this is a small thumbnail image</a> 

Here is the js for swapping the thumbnail:

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

now i want to access the id at the end of the thunbnail url. note this url is not a location url. thanks

A: 

Wrap your thumbnail imgs into anchors and set rel=<your_id> to them.
Then in jQuery you can access id via $('a.myclass').attr('rel'). So do I, maybe there are other better approaches.

Or maybe you provide some code here?

Darmen
here is what i have: <a href="test.ca/images/image-1.jpg?id=1"; onclick="swap(this); getVa(); return false;">this is a small thumbnail image</a> here is the js for swapping the thumbnail: function swap(image) { document.getElementById("main").src = image.href; } now i want to access the id at the end of the thunbnail url. note this url is not a location url. thanks
Menew
A: 

You can use the split() function to get the ID:

var url_split = image.href.split('=');
var id = url_split[1];

Why are you not using jQuery although you tagged your question this way?

Felix Kling
well i dont have an answer so i tagged whats easier to use. i will try your suggestion and see how that goes. thanks again
Menew
Well normally you tag the questions with those tags that belong to your problem. Obviously you don't have a problem with jQuery.
Felix Kling
ok so your suggestion worked. i have few more questions, maybe this will be jquery related. so the id that i get, i want to display it on the page. but the page has already load, so how can i display the value on a page that has already load. i dont want to use alert.
Menew
@Chocho: Reading the documentation of jQuery should help you: http://docs.jquery.com/Tutorials:Getting_Started_with_jQuery
Felix Kling
i actually got it! thanks, i used span id="", etc, etc. i am new to jquery. mayne thanks
Menew