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 7 of 7
  1. #1
    Regular Coder
    Join Date
    Nov 2005
    Posts
    750
    Thanks
    138
    Thanked 1 Time in 1 Post

    Validator problems

    Hello

    The online validator I use is issuing the following warnings:

    The "input" tag is in a form. Should the "name" attribute be used with this tag so that the form information can be submitted as a name/value pair?
    It refers to this:

    Code:
    <p><input type="text" id="lastName" /></p>
    Does the warning mean I have to do something like this:

    Code:
    <p>Surname:</p>
    <p><input type="text" name="name" value="lastName"></p>
    or can I use id="lastName" instead of value="lastName"?

    Thanks!

  • #2
    The fat guy next door VIPStephan's Avatar
    Join Date
    Jan 2006
    Location
    Halle (Saale), Germany
    Posts
    8,915
    Thanks
    6
    Thanked 1,040 Times in 1,013 Posts
    You should have a name attribute on your form controls. You don’t have to replace the ID, it can be present simultaneously; it can also have the same value as the ID. The value of the name attribute is used by server side scripts for processing.

  • #3
    Regular Coder
    Join Date
    Nov 2005
    Posts
    750
    Thanks
    138
    Thanked 1 Time in 1 Post
    Hello Stefan

    Thank you for your reply.

    I take it that I am not supposed to repeat name="name" for each field. I have just done that and get two errors:

    The control name "name" has already been used in this form and should not be used in this "input" tag.
    and

    The value of the "name" attribute ("name") may conflict with properties of the JavaScript Form object when using JavaScript. It is recommended .....
    There is no JavaScript anywhere on the page.

    The 'test' site is here:

    http://www.bayingwolf.com/display_recordsTEST.asp

    Do you think the validator means something like:

    Code:
    <p>First Name:</p>
    
    <p><input type="text" name="name" id="firstName" /></p>
    
    <p>Surname:</p>
    
    <p><input type="text" name="name1" id="lastName" /></p>
    
    <p>Tel No:</p>
    
    <p><input type="text" name="name2" id="telNo" /></p>
    The validator doesn't give any examples.

    Thanks for your help.

    Steve

  • #4
    Master Coder felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, Australia
    Posts
    6,642
    Thanks
    0
    Thanked 649 Times in 639 Posts
    When using both name and id on the same input field it is usual to use the same values for both fields (except for radio buttons where they must all have the same name but different ids).

    If you don't have any JavaScript in the page then you probably don't need the ids unless you are using them to apply specific styles in the CSS or the fields are the targets of links from elsewhere on the page or from other pages.

    The names you give the fields needs to correspond with how you intend to reference the values after the form is submitted.
    Stephen
    Learn Modern JavaScript - http://javascriptexample.net/
    Helping others to solve their computer problem at http://www.felgall.com/

    Don't forget to start your JavaScript code with "use strict"; which makes it easier to find errors in your code.

  • Users who have thanked felgall for this post:

    SteveH (09-13-2013)

  • #5
    Regular Coder
    Join Date
    Nov 2005
    Posts
    750
    Thanks
    138
    Thanked 1 Time in 1 Post
    Hello Stephen

    Using this

    Code:
    <p>Tel No:</p>
    
    <p><input type="text" name="telNo" id="telNo" /></p>
    
    <p>Address:</p>
    
    <p><input type="text" name="stAddress" id="stAddress" /></p>
    
    <p>City:</p>
    
    <p><input type="text" name="city" id="city" /></p>
    all the Validator warnings have disappeared!

    Many thanks for your help.

    Steve

  • #6
    The fat guy next door VIPStephan's Avatar
    Join Date
    Jan 2006
    Location
    Halle (Saale), Germany
    Posts
    8,915
    Thanks
    6
    Thanked 1,040 Times in 1,013 Posts
    Quote Originally Posted by felgall View Post
    If you don't have any JavaScript in the page then you probably don't need the ids unless you are using them to apply specific styles in the CSS or the fields are the targets of links from elsewhere on the page or from other pages.
    Or if you are using labels with your fields, which you should always do anyway.

    That said, Steve, your code would better look like this:
    Code:
    <div>
      <label for="telNo">Tel No</label>
      <input type="text" name="telNo" id="telNo" />
    </div>
    <div>
      <label for="stAddress">Address</label>
      <input type="text" name="stAddress" id="stAddress" />
    </div>
    <div>
      <label for="city">City</label>
      <input type="text" name="city" id="city" />
    </div>
    Each label’s for attribute corresponds to a field ID. Also, I got rid of the paragraph elements because what you have here is a form, not paragraphs of continuous text. You can use CSS to format the layout (e. g. by making the input fields display: block to go on the next line). And likewise you can use CSS to add the colons to the label text because that’s not actually relevant here. Use label:after {content: ':';}

  • Users who have thanked VIPStephan for this post:

    SteveH (09-14-2013)

  • #7
    Regular Coder
    Join Date
    Nov 2005
    Posts
    750
    Thanks
    138
    Thanked 1 Time in 1 Post
    Hello VIPStephan

    Very many thanks for that.

    I will need to try a few 'test runs' on your script ('label', etc) and to disgest those CSS attributes you refer to, so I have bookmarked this thread and saved the page. I will need to see how it looks on screen - and maybe get back to you if that's OK? - but what you say makes sense.

    Thanks again for your time and patience.

    Steve


  •  

    Posting Permissions

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