do we need id attribute??

M

Matt

I want to know if we need id attribute? Or just name attribute is fine?

For example:
Name: <input type="text" id="text" name="fname">
 
B

Bob Barrows

Matt said:
I want to know if we need id attribute? Or just name attribute is
fine?

For example:
Name: <input type="text" id="text" name="fname">

This is a matter of personal preference unless:

1. the element is in a form which you are submitting to an asp page, in
which case the name attribute must be set in order for the receiving page to
read its value.
2. the element is part of a group of elements which you need to refer to
with a single identifier. In this case, you should use the name attribute
for the grouping name, leaving the id attribute to be used for a unique name
for each element in the group. Radio buttons and checkboxes are often
created this way.

Otherwise, it's really up to you. My personal preference is to use id to
uniquely identify a single element on a page, and name for form elements and
grouped elements. In script, I will always use the id to refer to a single
element.

This is an HTML/DHTML question and should have been asked in a more
appropriate group (look for a group with "DHTML" in its name, or one of the
..scripting groups depending on which language you wish to use in your
client-side script). ASP (server-side code) knows nothing about element
names or ids.

HTH,
Bob Barrows
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,143
Messages
2,570,822
Members
47,368
Latest member
michaelsmithh

Latest Threads

Top