Ice3T
04-08-2003, 12:54 AM
What is the difference in using na ID or a NAME to refer to an object?
both seem to work fine.
both seem to work fine.
|
Click to See Complete Forum and Search --> : ID or NAME Ice3T 04-08-2003, 12:54 AM What is the difference in using na ID or a NAME to refer to an object? both seem to work fine. khalidali63 04-08-2003, 01:04 AM HTMLWise some elements has attribute name some don't same is with id, most of the elements as of today support id attribute, Name is mostly assosciated with form elements. DOM wise you can access one objects reference using getElementById where as getElementsByName wiill return an array of NodeList objects. Does this help? Cheers Khalid Ice3T 04-08-2003, 02:04 AM I dont know what a NodeList is so I dont understand much about getElementsByName But if I understand correctly I can give an object a name or an ID and will get the same effect also if I use an ID I can refer to that object using document.getElementById(objectsID). I dont really see how that is usefull since getElementById is such a long comand name to type. If I have a type=text input, ID=text1 in a form ID=form1 I could refer to its value as: document.text1.form1.value //in this case it doesnt matter if its an ID or name or document.getElementById('text1').value //in this case it must be an ID other than this is there a compatibility issue with Netscape? gil davis 04-08-2003, 05:45 AM The NAME attribute is used for forms, images, anchors and navigation. When you want to do navigation within the page, you can specify # and the desired NAME value in the link to navigate to that spot. There can be more than one object with the same name. This is helpful in forms where you have an array of checkboxes with the same name but different values. When the form is submitted, the only box submitted is the one checked, but regardless of which one is checked, the same name is passed (e.g.: ?someName=someValue). An ID must be unique. You cannot have more than one object with the same ID. For backward compatibility, if no NAME is specified, the browser will take the ID and copy it into the NAME attribute for you. You can specify styles by an ID, but not a NAME.<style> #someID {color: red} </style>As a general rule, use the property as intended and you will fare well. Think of an ID as a social security number or driver's licence - one per customer, but anyone can have the same name as yours. Ice3T 04-08-2003, 04:12 PM thanks Jona 04-08-2003, 04:16 PM Hey, Khalid, can you explain what a NodeMap is? I know it's something like an Array of nodes, right? webdeveloper.com
Copyright Internet.com Inc., All Rights Reserved. |