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 2 of 2
  1. #1
    New to the CF scene
    Join Date
    Nov 2006
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Noobie needs help

    I need to modify this html file to validate form field with javascript and alert when a specific field is left blank. Can anyone help. I know this is basic, but im still learning. Thanks.

    <!-- saved from url=(0022)http://internet.e-mail -->
    <!-- saved from url=(0022)http://internet.e-mail -->
    <html>
    <head>

    <title>Customer's Mailing List</title>


    <script language="JavaScript">
    <!-- Hide the following code
    function openDefinitionPage(URL) {
    myWindow=window.open(URL,"definition","toolbar=no,width=250, height=250,scrollbars=yes,resize=yes");
    }

    function validate()
    {
    if ((document.mlist.fname.value=="")||
    (document.mllist.lname.value=="")
    (document.mlist.email.value==""))
    {
    alert ("You must fill in all of the required .fields!")
    return false
    }
    }
    // End the hiding here -->
    </script>




    </head>
    <body>
    <h1>Join our mailing List!</h1>


    <form method="get" name="mlist" onsubmit="return validate()">

    <table>
    <tr>

    <td>First Name:</td>
    <td>

    <input type="text" name="fname" size="25" maxlength="25" />

    </td>
    </tr>
    <tr>
    <td>Last Name:</td>
    <td>

    <input type="text" name="lname" size="40" maxlength="40" />

    </td>
    </tr>

    <tr>
    <td>Address:</td>
    <td>

    <input type="text" name="addre" size="50" maxlength="50" />

    </td>
    </tr>


    <tr>

    <td>City:</td>
    <td>

    <input type="text" name="city" size="40" maxlength="40" />

    </td>
    </tr>
    <tr>
    <td>State:</td>
    <td>
    <select name="state" size="1">

    <option value="AL">Alabama</option>

    <option value="AK">Alaska</option>

    <option value="AZ">Arizona</option>

    <option value="CA" selected="selected">California</option>

    <option value="CO">Colorado</option>

    <option value="CT">Connecticut</option>

    <option value="DE">Delaware</option>

    <option value="DC">District of Colombia</option>

    <option value="FL">Florida</option>

    <option value="GA">Georgia</option>

    <option value="GU">Guam</option>

    <option value="HI">Hawaii</option>

    <option value="ID">Idaho</option>

    <option value="IL">Illinois</option>

    <option value="IN">Indiana</option>

    <option value="IA">Iowa</option>

    <option value="KS">Kansas</option>

    <option value="KY">Kentucky</option>

    <option value="LA">Louisiana</option>

    <option value="ME">Maine</option>

    <option value="MD">Maryland</option>

    <option value="MA">Massachusetts</option>

    <option value="MI">Michigan</option>

    <option value="MN">Minnesota</option>

    <option value="MS">Mississippi</option>

    <option value="MO">Missouri</option>

    <option value="MT">Montana</option>

    <option value="NE">Nebraska</option>

    <option value="NV">Nevada</option>

    <option value="NH">New Hampshire</option>

    <option value="NJ">New Jersey</option>

    <option value="NM">New Mexico</option>

    <option value="NY">New York</option>

    <option value="NC">North Carolina</option>

    <option value="ND">North Dakota</option>

    <option value="OH">Ohio</option>

    <option value="OK">Oklahoma</option>

    <option value="OR">Oregon</option>

    <option value="PA">Pennsylvania</option>

    <option value="PR">Puerto Rico</option>

    <option value="RI">Rhode Island</option>

    <option value="SC">South Carolina</option>

    <option value="SD">South Dakota</option>

    <option value="TN">Tennessee</option>

    <option value="TX">Texas</option>

    <option value="UT">Utah</option>

    <option value="VT">Vermont</option>

    <option value="VI">Virgin Islands</option>

    <option value="VA">Virginia</option>

    <option value="WA">Washington</option>

    <option value="WV">West Virginia</option>

    <option value="WI">Wisconsin</option>

    <option value="WY">Wyoming</option>

    </select>
    </td>
    </tr>

    <tr>

    <td>Phone:</td>

    <td>

    <input type="text" name="phone" size="10" maxlength="10"/>



    </td>
    </tr>

    <tr>

    <td>E-mail Address:</td>

    <td>

    <input type="text" name="email" size="40" maxlength="40" />

    </td>

    </tr>

    <tr>
    <td>Comments:</td>
    <td>

    <textarea name="comm" cols="40" rows="8"></textarea>
    </td>
    </tr>


    <tr>
    <td>&nbsp;</td>
    <td>

    <input type="submit" value="Click here to send" />
    </td>
    </tr>

    <tr>
    <td>&nbsp;</td>
    <td>

    <input type="reset" value="Reset form" />
    </td>
    </tr>

    </table>

    </form>

    </body>

    </html>

  • #2
    Kor
    Kor is offline
    Red Devil Mod Kor's Avatar
    Join Date
    Apr 2003
    Location
    Bucharest, ROMANIA
    Posts
    8,478
    Thanks
    58
    Thanked 379 Times in 375 Posts
    Is this of any help?
    Code:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"  "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head>
    <title>Untitled Document</title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    <meta http-equiv="Content-Style-Type" content="text/css">
    <meta http-equiv="Content-Script-Type" content="txt/javascript">
    <script type="text/javascript">
    var req=[
    ['fname','First Name'],
    ['lname','Last Name'],
    ['email','E-mail Address']
    ]
    /* 
    You may add above all the required fields ['name','text']
    Take care to leave the last element withouth a final comma
    */
    function validate(f){
    var i=0, e
    while(e=f[req[i++][0]]){
    if(e.value.length==0){
    alert('Please fill the field '+req[i-1][1])
    e.focus();
    return false
    }
    }
    }
    
    </script>
    </head>
    <body>
    <form action="" onsubmit="return validate(this)">
    First Name<input type="text" name="fname"><br>
    Last Name<input type="text" name="lname"><br>
    E-mail Address<input type="text" name="email"><br>
    <input type="submit" name="Sub" value="Submit">
    </form>
    </body>
    </html>
    KOR
    Offshore programming
    -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*


  •  

    Posting Permissions

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