SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Addict
    Join Date
    Jan 2007
    Posts
    296
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Help with form validation

    I am trying to create a form validation script for a website that we have. However I have hit problems due to the code been given to me by the software that we need to use with teh script.

    For the script to upload into our internal computer system i need to add the following code to the state validation section

    Code:
    var State = form.00N20000000wFV8.value;
    However this doesn't seem to be able to happen ( I am using dreamweaver and the .00 part is highlighted in red.

    How can I get around this as I need to use the code 00N20000000wFV8

    Full example below

    Code:
    <html>
    <head>
    <title>Login</title>
    <script type="text/javascript">
    function validate(form){
    var LastName = form.last_name.value;
    var Company = form.company.value;
    var State = form.00N20000000wFV8.value;
    
     if (LastName.length === 0) {
      alert("You must enter a last name.");
      return false;
     }
     
      if (Company.length === 0) {
      alert("You must enter a company.");
      return false;
     }
     
       if (State.length === 0) {
      alert("You must enter a state/County.");
      return false;
     }
    
     return true;
    }
    </script>
    </head>
    <body>
    <h1>Login Form</h1>
    <form method="post" action="Process.html" onsubmit="return validate(this);">
    
    <p class="pform">
    <label>First Name:</label>
    <input name="first_name" id="first_name" type="text" class="text" />
    </p>
    
    <p class="pform">
    <label><span class="required">*</span> Last Name:</label>
    <input name="last_name" id="last_name" type="text" class="text" />
    
    <p class="pform">
    <label><span class="required">*</span> Company:</label>
    <input name="company" id="company" type="text" class="text" />
    </p>
    
    <p class="pform">
    <label><span class="required">*</span> State:</label>
    <input name="00N20000000wFV8" id="00N20000000wFV8" type="text" class="text" />
    </p>
    
    
     <input type="submit" value="Submit">
     <input type="reset" value="Reset Form">
     </p>
    </form>
    </body>
    </html>
    Cheers

  2. #2
    SitePoint Evangelist TommiChi's Avatar
    Join Date
    Oct 2008
    Posts
    440
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Unless I am mistaken the name and ID attributes of an HTML tag cannot start with a number. Try putting a letter in the first position instead.

  3. #3
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,526
    Mentioned
    83 Post(s)
    Tagged
    3 Thread(s)
    While the id attriibute isn't allowed to be set or accessed in that manner, it's possible to access the named elements in the following manner:

    Code javascript:
    var State = form['00N20000000wFV8'].value;
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript


Bookmarks

Posting Permissions

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