Hi im having a nerve wrecking problem with my script, i'm trying to make a form validation that when a field is empty it will prompt a message that needs fo fill up the missing fields..and i made it already the problem is when i put a separate script for selectbox that dynamically change when the user try to select a category the validation code stop working..and i've already try everything that i can think of to solve it and with no avail..heres the code..
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<script type='text/javascript' src='jscript/jquery.min.js'></script>
<style type='text/css'>
</style>
<!------------------------SCRIPT FOR THE DYNAMICALLY CHANGE SELECTBOX-------------------------------------->
<script type='text/javascript'>//<![CDATA[
$(window).load(function(){
$(document).ready(function() {
$('#txtarea').change(function() {
$("#txtorigin").empty();
$("#txtdestination").empty();
$("#txtvehicle").empty();
$("<option value='0'>Select</option>").appendTo("#txtorigin");
$("<option value='0'>Select</option>").appendTo("#txtdestination");
$("<option value='0'>Select</option>").appendTo("#txtvehicle");
if ($(this).val() == "1") {
$("<option value='1'>NAIA 1</option>").appendTo("#txtorigin");
$("<option value='2'>NAIA 2</option>").appendTo("#txtorigin");
$("<option value='3'>NAIA 3</option>").appendTo("#txtorigin");
$("<option value='4'>Hotel Intercontinental Manila</option>").appendTo("#txtorigin");
$("<option value='5'>New World Hotel</option>").appendTo("#txtorigin");
$("<option value='6'>Best Western F1 Hotel</option>").appendTo("#txtorigin");
$("<option value='7'>Go Hotels Mandaluyong</option>").appendTo("#txtorigin");
$("<option value='8'>Tune Hotel-Malate</option>").appendTo("#txtorigin");
$("<option value='9'>Toyota VIOS 1.3 MT</option>").appendTo("#txtvehicle");
$("<option value='10'>Toyota VIOS 1300 E AT</option>").appendTo("#txtvehicle");
$("<option value='11'>Toyota VIOS 1500 G AT</option>").appendTo("#txtvehicle");
$("<option value='12'>Toyota ALTIS 1600 E MT</option>").appendTo("#txtvehicle");
$("<option value='13'>Toyota INNOVA 2.0 J GAS MT</option>").appendTo("#txtvehicle");
$("<option value='14'>Toyota INNOVA J Dsl MT</option>").appendTo("#txtvehicle");
$("<option value='15'>NAIA 1</option>").appendTo("#txtdestination");
$("<option value='16'>NAIA 2</option>").appendTo("#txtdestination");
$("<option value='17'>NAIA 3</option>").appendTo("#txtdestination");
$("<option value='18'>Hotel Intercontinental Manila</option>").appendTo("#txtdestination");
$("<option value='19'>New World Hotel</option>").appendTo("#txtdestination");
$("<option value='20'>Best Western F1 Hotel</option>").appendTo("#txtdestination");
$("<option value='21'>Go Hotels Mandaluyong</option>").appendTo("#txtdestination");
$("<option value='22'>Tune Hotel-Malate</option>").appendTo("#txtdestination");
}
else if ($(this).val() == "2") {
$("<option value='1'>Holiday Inn Clark Pampanga</option>").appendTo("#txtorigin");
$("<option value='2'>Tune Hotel - Clark</option>").appendTo("#txtorigin");
$("<option value='3'>Toyota VIOS 1.3 MT</option>").appendTo("#txtvehicle");
$("<option value='4'>Toyota INNOVA 2.0 J GAS MT</option>").appendTo("#txtvehicle");
$("<option value='5'>Toyota INNOVA J Dsl MT</option>").appendTo("#txtvehicle");
}
else if ($(this).val() == "3") {
$("<option value='1'>Summit Circle Hotel</option>").appendTo("#txtorigin");
$("<option value='2'>Mactan Cebu International Airport</option>").appendTo("#txtorigin");
$("<option value='3'>Cebu Regional Office</option>").appendTo("#txtorigin");
$("<option value='4'>Toyota VIOS 1300 E AT</option>").appendTo("#txtvehicle");
$("<option value='5'>Toyota VIOS 1500 G AT</option>").appendTo("#txtvehicle");
$("<option value='6'>Toyota INNOVA J Dsl MT</option>").appendTo("#txtvehicle");
}
else if ($(this).val() == "4") {
$("<option value='1'>Davao International Airport</option>").appendTo("#txtorigin");
$("<option value='2'>Airport View Hotel</option>").appendTo("#txtorigin");
$("<option value='4'>Marco Polo Hotel</option>").appendTo("#txtorigin");
$("<option value='5'>Pearl Farm Beach Resort</option>").appendTo("#txtorigin");
$("<option value='6'>3 Star Hotel (The Royal Mandala Hotel )</option>").appendTo("#txtorigin");
$("<option value='7'>Toyota VIOS 1.3 MT</option>").appendTo("#txtvehicle");
$("<option value='8'>Toyota VIOS 1500 G AT</option>").appendTo("#txtvehicle");
$("<option value='9'>Toyota INNOVA 2.0 J GAS MT</option>").appendTo("#txtvehicle");
$("<option value='10'>Toyota INNOVA J Dsl MT</option>").appendTo("#txtvehicle");
}
else if ($(this).val() == "5") {
$("<option value='1'>Gen Santos International Airport</option>").appendTo("#txtorigin");
$("<option value='2'>Suncity Suites</option>").appendTo("#txtorigin");
$("<option value='7'>Toyota VIOS 1.3 MT</option>").appendTo("#txtvehicle");
$("<option value='9'>Toyota INNOVA 2.0 J GAS MT</option>").appendTo("#txtvehicle");
$("<option value='10'>Toyota INNOVA J Dsl MT</option>").appendTo("#txtvehicle");
}
});
});
});//]]>
</script>
<script language="javascript">
function validate()
{
var x=document.forms["form2"]["txtarea"].value;
if (x==null || x=="Select")
{
alert("Please select area");
return false;
}
var x=document.forms["form2"]["txtorigin"].value;
if (x==null || x=="Select")
{
alert("Please select origin");
return false;
}
var x=document.forms["form2"]["txtdestination"].value;
if (x==null || x=="Select")
{
alert("Please select destination");
return false;
}
var x=document.forms["form2"]["txtvehicle"].value;
if (x==null || x=="Select")
{
alert("Please select vehicle");
return false;
}
}
// -->
</script>
</head>
<body>
<form name="form2" method="post" action="a.html" onSubmit="return validate()">
<p>
<select id='txtarea' name="txtarea">
<option value="0">Select</option>
<option value="1">Metro Manila</option>
<option value="2">Pampanga</option>
<option value="3">Cebu</option>
<option value="4">Davao</option>
<option value="5">Gen. Santos</option>
</select>
<br/>
<br/>
<select id='txtorigin' name="txtorigin">
<option value="Select">Select</option>
</select>
<select id='txtdestination' name="txtdestination">
<option value="Select">Select</option>
</select>
<select id='txtvehicle' name="txtvehicle">
<option value="Select">Select</option>
</select>
</p>
<label>
<input type="submit" name="Submit" value="Submit">
</label>
</form>
<p> </p>
<p> </p>
<p> </p>
<p></p>
<p> </p>
</body>
</html>