Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8299167
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T16:03:44+00:00 2026-06-08T16:03:44+00:00

I’ve a long time habit when coding to name most of the fields in

  • 0

I’ve a long time habit when coding to name most of the fields in a HTML form with matching “name” and “id” attributes, when possible. This allows me to simplify dynamic HTML generation, f. ex. creating a dropdown in PHP with:

select("myselect", $values);

instead of:

select("myselect", "myselectId", $values)

making also my element immediately available for selectors like those in JQuery (for validation etc.).

I know this solution has some issues (it is not good for radio buttons and checkboxes arrays – and for that I include an $id parameter in my PHP functions for radios -, it mixes two attributes meant for different purposes, it may cause problems when more than one form is on the page).

Is this bad habit really that bad? Have I overlooked some other possible negative side-effects?
What would you do in my place?

  • Stick to this whenever it’s not causing any problem
  • Do not use “ids” at all and use appropriate selectors for JQuery, like $(form[name='...'] input[name='...']).somefunction()
  • Code in every single element a different id?
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T16:03:46+00:00Added an answer on June 8, 2026 at 4:03 pm

    Giving an element matching names and ids does not cause a problem, so you don’t need to worry about it and it is not bad practise.

    Related things that do cause problems:

    • Giving multiple elements the same id (e.g. if you have a radio button group where each member has to have the same name).
    • Giving one element a name and a different element a matching id

    Do not use “ids” at all

    If you don’t give a form control an id, then you can’t use a for attribute to associate it with a <label> element. Support for for attributes is slightly better then for making the form control a descendent of the label. Since labels are really useful for accessibility (they increase the size of the click target and give a non-visual association between the control and the input) leaving ids off is not a good idea.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have this code to decode numeric html entities to the UTF8 equivalent character.
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have a text area in my form which accepts all possible characters from
Is it possible to replace javascript w/ HTML if JavaScript is not enabled on
For some reason, after submitting a string like this Jack’s Spindle from a text
this is what i have right now Drawing an RSS feed into the php,
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
Does anyone know how can I replace this 2 symbol below from the string

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.