Forum Moderators: open
The function SetValue(obj) is supposed to set a textfield to the inner HTML part of the clicked span. I do this by accessing the object by this.innerHTML. This works flawlessly in Firefox, Opera and Konqeror. Only Internet Explorer won't do anything.
My spans look like this:
<span class="foo"><a href="#" onclick="SetValue(this);">My value 1</a></span>
How can I access the HTML part of the span's anchor tag? Basically I wouldn't need the anchor tag, since they are no real links, but I added them, because I don't want to do the hover effect with javascript, and IE doesn't support hover for other elements than anchor tags.
Thanks in advance!
The script you posted works for me, too. But I guess there is a difference between your script and mine that keeps IE from showing the innerHTML part.
My script generates the spans on the fly like this:
locations = array("foo", "bar", "foobar", "barfoo");
for (i = 0; i < locations.length; i++) {
buffer = buffer + '<span><a href="#" onclick="setValue(this);">'+locations[i]+'</a></span>';
}
document.getElementById('dropdownlist').innerHTML = buffer;
dropdownlist now contains a list of spans. I guess IE cannot understand that it is supposed to add 'this' as a literal string rather than evaluating it.
How can I rewrite the function, that 'this' is replaced by locations[i]? I can't seem to get it working because of the apostrophes.
Thanks
locations = [blue]A[/blue]rray("foo", "bar", "foobar", "barfoo");
buffer = "";for (k = 0; k < locations.length; k++)
buffer = buffer + '<span><a href="#" onclick="setValue(this);">'+locations[k]+'</a></span>\n';alert(buffer);
This produces the desired string (the strings wrapped in tags).
What do you mean by this?:
...it is supposed to add 'this' as a literal string rather than evaluating it.
It produces wrappings like:
<span><a href="#" onclick="setValue(this);">foo</a></span>
This is OK, isn't it. this isn't evaluated.
God Jul!