Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    New Coder
    Join Date
    Nov 2005
    Posts
    18
    Thanks
    0
    Thanked 0 Times in 0 Posts

    multiple fields with same name?

    hi, ive got a form with several fields with the same name, though only one is enabled at a time. This works when i submit the data, ie only the enabled field data gets submitted, but my javascript doesnt like reading/changing the values of the enabled field. it doesnt seem to like the fact that ive got more than one field with the same name

    is changing the field names so that they are all unique my only option here to get javascript to like my form??

  • #2
    Master Coder
    Join Date
    Feb 2003
    Location
    UmeŚ, Sweden
    Posts
    5,575
    Thanks
    0
    Thanked 83 Times in 74 Posts
    The only form controls that may share control name with other controls are radio buttons and checkboxes. Don't expect browsers to support multiple controls with the same name if they are not of those types.
    liorean <[lio@wg]>
    Articles: RegEx evolt wsabstract , Named Arguments
    Useful Threads: JavaScript Docs & Refs, FAQ - HTML & CSS Docs, FAQ - XML Doc & Refs
    Moz: JavaScript DOM Interfaces MSDN: JScript DHTML KDE: KJS KHTML Opera: Standards

  • #3
    Senior Coder
    Join Date
    Feb 2004
    Location
    Edinburgh
    Posts
    1,352
    Thanks
    0
    Thanked 0 Times in 0 Posts
    doesn't creating field names with the same name create an array of those fields, even for non-radio fields? In PHP, you can iterate over this array, and extract their respective values.
    *keep it simple (TM)

  • #4
    Master Coder
    Join Date
    Feb 2003
    Location
    UmeŚ, Sweden
    Posts
    5,575
    Thanks
    0
    Thanked 83 Times in 74 Posts
    Quote Originally Posted by jbot
    doesn't creating field names with the same name create an array of those fields, even for non-radio fields? In PHP, you can iterate over this array, and extract their respective values.
    In some implementations, yes. But they do that not because they have to do it to follow the specification, they do it as a way to gracefully handle code that doesn't follow the specification. In other words, you can't count on it since they could as well just always use the first element, or always the last element, or only the last to be changed. They could even set all the fields to the value entered in just one of them. And they would still follow the spec.
    liorean <[lio@wg]>
    Articles: RegEx evolt wsabstract , Named Arguments
    Useful Threads: JavaScript Docs & Refs, FAQ - HTML & CSS Docs, FAQ - XML Doc & Refs
    Moz: JavaScript DOM Interfaces MSDN: JScript DHTML KDE: KJS KHTML Opera: Standards

  • #5
    Regular Coder
    Join Date
    Sep 2005
    Posts
    535
    Thanks
    0
    Thanked 0 Times in 0 Posts
    As liorean stated, it may not be to spec., but you could use unique id's while keeping the names the same... Or use getElementsByName() and use the collection to get the specific element that you want. But if you're trying for lasting code, then its better to get as close to spec. as possible; then you won't have to continually maintain the code to make sure it works with newer browsers.

    Oh, and another FYI about the name attribute: in XHTML (which some have claimed will be the spec.s for the next version of HTML), the name attribute has become depricated for some non-form elements in place of the id attribute. Although this doesn't affect your code with naming the text boxes, it would affect <div>s and <img>s that you may use elsewhere in your code...
    If you want answers, write a smart question.

    Yes, someone probably does know how...

    Oh, and if you want to learn, STFW!


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •