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 Coder
    Join Date
    Feb 2005
    Posts
    44
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Javascript Validation

    Hello,

    I have the following form and i need to validate wht the user has inputted when they press the SEARCh button.

    <form method="POST" action="metaSearch.php">
    <table border="0" width="100%" id="table14" cellspacing="0" cellpadding="2">
    <tr>
    <td><input type="text" name="query" size="50" maxlength="100"></td>
    </tr>
    <tr>
    <td>
    <select size="1" name="category">
    <option selected value="">Please Select...</option>
    <option value="Antiques">Antiques</option>
    <option value="Art">Art</option>
    <option value="Books">Books</option>
    <option value="Cameras & Photo">Cameras & Photo</option>
    <option value="Clothing, Shoes & Accesories">Clothing, Shoes & Accesories</option>
    <option value="Coins">Coins</option>
    <option value="Computers & Networking">Computers & Networking</option>
    <option value="Consumer Electronics">Consumer Electronics</option>
    <option value="Entertainment">Entertainment</option>
    <option value="Electrical">Electrical</option>
    <option value="Home & Garden">Home & Garden</option>
    <option value="Music">Music</option>
    <option value="Real Estate">Real Estate</option>
    <option value="Toys & Hobbies">Toys & Hobbies</option>
    <option value="Travel">Travel</option>
    <option value="Other">Other..</option>
    </select>
    </td>
    </tr>
    <tr>
    <td>
    <select size="1" name="site">
    <option selected value="all">All Auction Sites</option>
    <option value="cqout">CQOUT Auctions</option>
    <option value="ebid">EBID Auctions</option>
    <option value="qxl">QXL Auctions</option>
    </select>
    </td>
    <td>
    <input type='submit' name="search" value="Search" onMouseover="write_it('::Click to Search....');return true;" onMouseout="write_it('');return true;" style="float: right">
    </td>
    </tr>
    </table>

    I need a script that checks to make sure, the textfield is not empty doesnt matter what is typed in, just check if empty. And check if a category has been selected other than the selected value.

    If anyone can help i would be most grateful.

    Thxs.
    -----------------------------------------------

  • #2
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    11,048
    Thanks
    0
    Thanked 251 Times in 247 Posts
    Code:
    <head>
    <script type="text/javascript">
    function validate(frm){
      if (f.query.value==""){
        alert("Please specify query.");
        f.query.focus();
        return false;
      }
      if (f.category.selectedIndex==0){
        alert("Please select category.");
        f.category.focus();
        return false;
      }
      return true;
    }
    </script>
    </head>
    <body>
    <form method="POST" action="metaSearch.php" onsubmit="return validate(this)">


  •  

    Posting Permissions

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