View Full Version : Javascript Validation

03-17-2005, 10:33 AM

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">
<td><input type="text" name="query" size="50" maxlength="100"></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 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>
<input type='submit' name="search" value="Search" onMouseover="write_it('::Click to Search....');return true;" onMouseout="write_it('');return true;" style="float: right">

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. :)

03-17-2005, 10:54 AM
<script type="text/javascript">
function validate(frm){
if (f.query.value==""){
alert("Please specify query.");
return false;
if (f.category.selectedIndex==0){
alert("Please select category.");
return false;
return true;
<form method="POST" action="metaSearch.php" onsubmit="return validate(this)">