...

View Full Version : Javascript Validation



benni
03-17-2005, 09:33 AM
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. :)

glenngv
03-17-2005, 09:54 AM
<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)">



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum