hello i have list box on the screen and when i send data to a text box the slect another item in the list box the page reloads. The problem is the data in the textbox disappears
<html>
<head>
<title>Route Planner</title>
</head>
<body>
<script language="JavaScript" type="text/JavaScript">
function AddTown() {
var theForm1 = document.forms["form1"];
var theForm2 = document.forms["form2"];
var sdata1 = theForm2.town.options[theForm2.town.options.selectedIndex].value;
var sdata2 = theForm2.country.options[theForm2.country.options.selectedIndex].value;
if (theForm1.town1.value == "") {
theForm1.town1.value = sdata1
theForm1.county1.value = sdata2
}
else if (theForm1.town2.value == "") {
theForm1.town2.value = sdata1
theForm1.county2.value = sdata2
}
else if (theForm1.town3.value == "") {
theForm1.town3.value = sdata1
theForm1.county3.value = sdata2
}
else {
alert(sdata1)
}
}
</script>
<p> </p>
<form name="form1" method="post" action="RoutePlanner2.php">
<table width="98%" border="0">
<tr>
<td width="13%">Town 1 </td>
<td width="31%"><input name="town1" type="text" id="town1">
<input name="county1" type="text" id="county1" size="6" maxlength="2"> </td>
<td colspan="2" rowspan="6">
</td>
</tr>
<tr>
<td>Town 2 </td>
<td><input name="town2" type="text" id="town22">
<input name="county2" type="text" id="county2" size="6" maxlength="2"></td>
</tr>
<tr>
<td>Town 3 </td>
<td><input name="town3" type="text" id="town32">
<input name="county3" type="text" id="county3" size="6" maxlength="2"></td>
</tr>
<tr>
<td>Start time </td>
<td><input name="StartTime" type="text" id="StartTime2" size="10" maxlength="5"></td>
</tr>
<tr>
<td>Stop duration </td>
<td><input name="StopDuration" type="text" id="StopDuration2" size="10" maxlength="5"></td>
</tr>
<tr>
<td>Speed (mph)</td>
<td><input name="Speed" type="text" id="Speed2" size="6" maxlength="3"></td>
</tr>
<tr>
<td><input name="submit" type=submit></td>
<td> </td>
<td width="21%"> </td>
<td width="35%"> </td>
</tr>
</table>
</div>
</form>
<form name="form2" method="post" action="RoutePlanner.php">
<?php error_reporting(E_ALL);
/* open the data file */
$t=0;
$fn = file("townsx","r");
/* now to read the files record by record */
foreach($fn as $rec)
{
$elem = explode(":",$rec);
/* split each record into fields (: is separator) */
$countryarray[] = array($elem[0], $elem[1], $elem[2], $elem[3], $elem[4], $elem[5]);
}
echo"<select name=\"country\" onchange=\"document.forms['form2'].submit()\" size=\"10\">";
if(isset($_POST['country']))
{
$check[]=$_POST['country'];
}
else
{$check=array();$t++;
}
foreach($countryarray as $key => $array)
{
if(!in_array($array[1],$check))
{
$check[]=$array[1];
if($t==0)
{
echo"<option value=\"$check[0]\" selected>$check[0]</option>";
$t++;
}
else
{
echo"<option value=\"$array[1]\">$array[1]</option>";
}
}
}
echo"</select>";
if(isset($_POST['country']))
{
$countryid=$_POST['country'];
echo"<select name=\"town\" size=\"10\">";
foreach($countryarray as $key => $carray)
{ echo $countryid."-".$carray[1];
if($countryid==$carray[1])
{
echo"<option value=\"$carray[0]\">$carray[0]</option>";
}
}
echo"</select>";
}
?> </form>
<input name="Add" type=button id="Add" onClick="AddTown()" value="Add"/>
</body>
</html>