473,406 Members | 2,705 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

Error: document.getElementsByName(userid)[0] has no properties

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

May 8 '06 #1
4 7952
alert(document.getElementsByName(userid)).

Check if you really got an object. I guess not.

May 8 '06 #2
da**********@gmail.com said the following on 5/8/2006 5:44 AM:
I got the following error in a javascript I wrote. The script works
fine, but why is the error being displayed???


Evidently it doesn't "work fine" or you wouldn't get the error.
You get the error because there is an error in your code.

What is the error message?

Your problem probably lies in the area of you passing the function a
string parameter to try to access an object that doesn't exist.

--
Randy
comp.lang.javascript FAQ - http://jibbering.com/faq & newsgroup weekly
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
May 8 '06 #3
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

May 8 '06 #4
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???
Because the code is junk^W error-prone.
##### 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; }

#####


<URL:http://pointedears.de/scripts/test/whatami#inference>
<URL:http://rfc-editor.org/rfc/rfc3986.txt>
PointedEars
--
When the power of love overcomes the love
of power, the world will know peace.
-- Jimi Hendrix
May 17 '06 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: CJ | last post by:
Hi In my PHP script I'm able to update bookmarks without in hassles but document properties just don't work! I know in VB custom properties can be changed with the following: ...
3
by: StrongBad | last post by:
Does anyone know of a way to access the document properties of an office document using ASP? I need to be able to read things like the Title, Author, and Comments fields and pull that information...
1
by: Patrick Conway | last post by:
Hi! I'm building a Windows form that allows users to view a list of files (and their properties(metadata)) stored in a certain directory. All of the files in the directory are a result of a...
4
by: Craig | last post by:
I'm trying to build a filter for a file search where the search will be able to filter out certain files according to certain "file properties", like Owner, Creation Date, etc. MS does this in...
0
by: clintonG | last post by:
Does somebody have code or documented methodology that will audit controls in the framework to generate the names and values for the properties each control uses? <%= Clinton Gallagher...
0
by: Alan T | last post by:
I have modified custom properties of a Word document by code. And there are fields in this Word document link to the properties, however, after running the application and reopen the document, the...
4
by: Morgan | last post by:
Hello! I'm trying to find out if it's possible to access the properties of an document uploaded via the fileupload control? The end goal is to dynamically insert the number of pages in a document...
0
by: Support | last post by:
Hello: Apparently we can read and write to Document Properties using Dsofile.dll (seel http://support.microsoft.com/?id=224351) My question is: can this be extended to non-native Microsoft...
0
by: hannahhhh1056 | last post by:
Hello! I´m trying to create a makro that finds the text in a wddocument formatted as "heading 1" and then puts it in the document properties. I know how to get the text into doc properties but i...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.