www.webdeveloper.com
Results 1 to 3 of 3

Thread: [RESOLVED] My js code wont validate my form info

  1. #1
    Join Date
    Nov 2010
    Location
    Caribbean
    Posts
    2

    resolved [RESOLVED] My js code wont validate my form info

    This is my html code

    HTML Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
    
    <html>
    <head>
    
      <script language="javascript" type="text/javascript">
    //<![CDATA[
    
      <!-- hide script from older browsers
      function validateForm(contact)
      {
    
      if(""==document.forms.contact.firstname.value)
      {
      alert("Please enter your full name.");
      return false;
      }
    
      if(""==document.forms.contact.email.value)
      {
      alert("Please enter your email address.");
      return false;
      }
    
      if(""==document.forms.contact.telephone.value)
      {
      alert("Please enter your phone number.");
      return false;
      }
    
      }
      stop hiding script -->
      //]]>
      </script>
    
      <title>Newsletter</title>
      <link rel="stylesheet" type="text/css" href="format.css" media="screen" />
    </head>
    
    <body>
      <h1>Sunset Human Resource Department</h1>
    
      <div id="left">
        <h4>Location: Mount Pleasant, Antigua<br />
        Telephone: 268-248-4343<br />
        Email: sunset@sun.com<br /></h4>
    
        <center>
          <h4><a href="your_url_goes_here"><img src="sunset.jpg" onmouseover=
          "this.src='sunsetMouse.jpg';" onmouseout="this.src='sunset.jpg';" alt=
          "Hover to reveal new image" width="300" height="200" border="0" /></a> <img src=
          "workingpeople.jpg" width="300" height="200" alt="workingpeople" /></h4>
        </center>
      </div>
    
      <div id="right">
        <p>A corporate culture&hellip;</p>
    
        <ul>
          <li>can be described as a feeling of unity among all levels and divisions of an
          organization&mdash;employees, managers, the C-level, the marketing department, the
          HR department and so on.</li>
    
          <li>can be seen throughout all aspects of the organization, including office setup,
          atmosphere, professional environment, communication styles and dress code.</li>
        </ul>(must consist of 6 line spaces) (H6)Credits
      </div>
    
      <div id="middle">
        <p>Corporate Culture</p>
    
        <p>Corporate culture is more than just a passing trend in HR because of the impact it
        can have, and is having, if executives and staff members are involved in its creation
        and proliferation. It helps create success for business initiatives, can cut costs in
        recruiting, and increases overall employee satisfaction and productivity. However,
        corporate culture is about more than having free Coca-tda in the fridge and allowing
        employees to take their dogs to the office. Culture is how employees describe where
        they work, understand the business, and see themselves as part of the organization.
        Building a strong company culture will not itself guarantee business success, but
        culture is a key determinant in attracting talent&mdash;and it is that talent that
        carries a company forward. Corporate culture is often defined as &ldquo;the
        attitudes, experiences, beliefs and values of an organization.&rdquo; 1 In a recent
        TriNet survey, business executives reported that building a company culture is the
        aspect of strategic HR they feel is most important to their businesses. The bottom
        line? Companies that truly live their corporate cultures are higher performing and
        better places to work than companies that lack these cultures. Below are the top ten
        ways in which a distinct corporate culture will impact your business.</p>
      </div><br />
      <br />
      <br />
      <br />
      <br />
    
      <form name="contact" method="post" action="http://somesite.com/prog/adduser" onsubmit=
      "return validateForm(contact);" id="contact">
        <p><label for="firstname">First name:</label> <input type="text" id=
        "firstname" /><br />
        <label for="lastname">Last name:</label> <input type="text" id="lastname" /><br />
        <label for="email">Email Address:</label> <input type="text" id="email" /><br />
        <label for="telephone">Telephone Number:</label> <input type="text" id=
        "telephone" /><br />
        <input type="radio" name="sex" value="Male" /> Male<br />
        <input type="radio" name="sex" value="Female" /> Female<br />
        <input type="button" value="Submit" /> <input type="reset" /></p>
      </form>
    </body>
    </html>

  2. #2
    Join Date
    Apr 2003
    Location
    Netherlands
    Posts
    21,654
    Raw text in script; the commenting is incorrect and unnecessary unless you are sending the document as "content-type: application/xhtml+xml" to supporting browsers
    Code:
      <script type="text/javascript">
      function validateForm(contact)
      {
    
      if(""==document.forms.contact.firstname.value)
      {
      alert("Please enter your full name.");
      return false;
      }
    
      if(""==document.forms.contact.email.value)
      {
      alert("Please enter your email address.");
      return false;
      }
    
      if(""==document.forms.contact.telephone.value)
      {
      alert("Please enter your phone number.");
      return false;
      }
    
      }
      </script>
    Incorrect input type
    Code:
    <input type="submit" value="Submit" />
    Passing an undefined variable, pass a string (this argument is never used in script)
    Code:
    onsubmit=
      "return validateForm('contact');"
    At least 98% of internet users' DNA is identical to that of chimpanzees

  3. #3
    Join Date
    Nov 2010
    Location
    Caribbean
    Posts
    2
    Thanks alot! Running perfectly now!

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles