ID vs Name in forms

Hi,

Been trying to work out the difference between ID and Name, ID only allows unique ID's while Name can be the same?

But what is there actual use in an email form?
LVL 2
SideasAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

flow79Commented:
ID is normally used when setting specific styles in CSS, or when accessing an element in Javascript (getElemenyById).  

the name is used when calling the actual form or elements.

<form method="POST" name="form1" action="yourpage.asp">
  <input type="text" name="yourinput" />
  <input type="submit" value="Submit" />
</form>

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
BatalfCommented:
Yes, IDs should be unique. This gives you the possibility to refer to them in Javascript by use of document.getElementById().

The name of your form fields should also be unique. The only exception is radio buttons where you use the same name on all the buttons in a group.

The name of your form fields is what is sent to server when the form is submitted. So if you for example have two text fields with the same name, only one of them is sent to the server.

Batalf
flow79Commented:
<style>
#form1 { background-color: #ff0000; }
</style>

<script>
 obj1 = document.getElementById('form1')
</script>

<form method="POST" name="form1" action="yourpage.asp" id="form1">
  <input type="text" name="yourinput" />
  <input type="submit" value="Submit" />
</form>
Your Guide to Achieving IT Business Success

The IT Service Excellence Tool Kit has best practices to keep your clients happy and business booming. Inside, you’ll find everything you need to increase client satisfaction and retention, become more competitive, and increase your overall success.

SideasAuthor Commented:
Thank you guys, that was insanely fast :0)

I gave points to flow79 as he got in first by 1 minute! But you both gave great answers, but i have to give it to the first one to post (i read via the rules). If im wrong let me know.

Thank you both :0)
BatalfCommented:
It's common practice to split points between comments posted about the same time, but it doesn't matter to me. Just leave it as it is :^)

Batalf
SideasAuthor Commented:
Ok Batalf, thx i'll remember to split them next time, if times are close between postings.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Web Languages and Standards

From novice to tech pro — start learning today.