da**********@gmail.com wrote:
I got the following error in a javascript I wrote. The script works
fine, but why is the error being displayed???
##### Here comes the little script:
function chgMusicLink(userid,userlink,usertype) {
var card_music_id = document.getElementsByName(userid)[0].value;
document.getElementsByName(userlink)[0].href="/card_music_preview.tcl?card_music_id="+card_music_ id+"&card_music_type="+usertype;
}
#####
Thanks
Does the error appear in IE but not Firefox?
If this is the case then it is because IE does not recognise the name
attributes in most tags, for example getElementsByName will return an
empty list when the only matching name attributes are in divs.
The explanation I plagiarised and the list of tags IE recognises is
here
http://jszen.blogspot.com/2004/07/whats-in-name.html
A possible drawback to relying on getElementsByName is that the name
attribute has been deprecated in XHTML1.0 and the w3c plan to remove
it altogether, they have already replaced the name attribute with id
for <a> and <map> in the current XHTML1.1 proposal.
A solution is to use a different attribute, (most likely id or
classname, would consider title if I get desperate), then use a
function that walks over the dom or a nodelist (if you use
getElementsByTagname to reduce the number of nodes searched) to find a
match.
You could do this yourself but there are plenty of pre-written versions
that do this, unfortunately I can't remember where any are.
Hope this helps
Tim