Hello and welcome to our community! Is this your first visit?
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
    Dec 2010
    Thanked 0 Times in 0 Posts

    PHP forms with Javascript Validation

    I have an edit form with Javascript validation. The validation never gets executed. Please look at the following abbreviated code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml" dir="ltr" lang="en-US" xml:lang="en">

    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=EmulateIE7" />
    <title> </title>

    <script type="text/javascript" src="script.js"></script>
    <script type="text/javascript">

    function validate(form){

    if (form1.zip.length !== 5) {
    alert("You must enter a zipcode with five characters.");
    return false;

    return true;


    include ("db.php");
    $tbl_name="client"; // Table name

    // Connect to server and select database.
    mysql_connect("$host", "$username", "$password")or die("cannot connect");
    mysql_select_db("$db_name")or die("cannot select DB");

    // get value of id that sent from address bar

    // Retrieve data from database
    $sql="SELECT * FROM $tbl_name WHERE id='$id'";


    <table width="300" border="0" align="center" cellpadding="0" cellspacing="1">
    <td><form name="form1" method="post" onsubmit="return validate(this)"></td>
    <table width="100%" border="0" cellspacing="1" cellpadding="3">
    <td colspan="4"><strong> Update Client </strong></td>
    <td width="30%" align="right">First Name:</td>
    <td ><input name="firstname" type="text" id="firstname" value="<? echo $rows['firstname']; ?>"></td>
    <td width="30%" align="right">Last Name:</td>
    <td><input name="lastname" type="text" id="lastname" value="<? echo $rows['lastname']; ?>"></td>
    <td width="30%" align="right">Address1:</td>
    <td><input name="address1" type="text" id="address1" value="<? echo $rows['address1']; ?>"></td>
    <td width="30%" align="right">Address2:</td>
    <td><input name="address2" type="text" id="address2" value="<? echo $rows['address2']; ?>"></td>
    <td width="30%" align="right">City:</td>
    <td><input name="city" type="text" id="city" value="<? echo $rows['city']; ?>"></td>
    <td width="30%" align="right">State:</td>
    <td><input name="state" type="text" id="state" value="<? echo $rows['state']; ?>"></td>
    <td width="30%" align="right">Zip:</td>
    <td><input name="zip" type="text" id="zip" value="<? echo $rows['zip']; ?>"></td>
    <td width="30%" align="right">Country of Origin: </td>
    <td><input name="selcountry" type="text" id="country" value="<? echo $rows['country']; ?>"></td>
    <td width="30%" align="right">Birth Date:</td>
    <td><input name="birth" type="text" id="birth" value="<? echo $rows['birth']; ?>"></td>

    <td colspan="3" align="center"><input type="submit" name="Submit" value="Submit" ></td>




  2. #2
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    London, England
    Thanked 2,703 Times in 2,679 Posts
    See:- http://www.codingforums.com/showthread.php?t=17515.

    You will not get any reply in this forum which is intended to be used only to
    post a completed (working) script for showcasing/benefit of others.

    Before you post again please read the forum rules and posting guidelines.


Posting Permissions

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