Hi,
i want to make a menu with 2 combos and 2 text boxes. when 1st combo changes, second combo is updated automatically (using onchange.submit()), and i have 2 more text boxes.
The problem is, i want to have a submit button, and when pressed it will execute a function in the index.php with the last changes from all the 4 inputs.
- i have triyed in the same form, but this way, i dont know if the submit was executed by the button or by the change in the 1st combo box(onchange.submit()).
- if i use another form i lose last data from text boxes
Can someone help me !!!
Here's the problem source.
thanks in advance
//##############
//Index.php
//##############
include "funcs.php";
print "INDEX state ".$state."<br>";
print "INDEX city ".$city."<br>";
print "INDEX date ".$date."<br>";
print "INDEX phone ".$phone."<br>";
if ($state=="")$state="stateA";//1;
if ($savebutton=='1')print "Function to save";
$savebutton=0;
ask_data($state,$city,$date,$phone);
//############
//FUNCS.PHP
//#############
function ask_data($state,$city,$date,$phone)
{
$states=array('stateA','stateB');
$city1=array("StateAcity1","StateAcity2","StateAci ty3");
$city2=array("StateBcity1","StateBcity2","StateBci ty3");
?>
<table width="735" border="1" cellspacing="0" cellpadding="0">
<tr>
<td align=center><br>State 
<form method="POST" enctype='application/x-www-form-urlencoded' style="word-spacing: 0; margin-top: 0; margin-bottom: 0" name="formstate" action="index.php">
<select name="state" onchange=formstate.submit() >
<? for ($i=0;$i<sizeof($states);$i++)
if ($state==$states[$i])
print "<option selected value=".$states[$i].">".$states[$i]."</option>";
else
print "<option value=".$states[$i].">".$states[$i]."</option>";
?>
<input type='hidden' name='city' value=<?echo $city?>>
<input type='hidden' name='phone' value=<?echo $phone?>>
<input type='hidden' name='date' value=<?echo $date?>>
</select>
</td>
<tr>
<td align=center>
City <br>
<?
if ($state=='stateA') $citys=$city1;
else $citys=$city2;
?>
<select name="city" onchange=formstate.submit() >
<?
for ($i=0;$i<sizeof($citys);$i++)
if ($city==$citys[$i])
print "<option selected value=".$citys[$i].">".$citys[$i]."</option>";
else
print "<option value=".$citys[$i].">".$citys[$i]."</option>";
?>
<input type='hidden' name='phone' value=<?echo $phone?>>
<input type='hidden' name='date' value=<?echo $date?>>
</select>
</td>
<tr>
<tr>
</table>
<table width="735" border="1" cellspacing="0" cellpadding="0">
<tr>
<td align=center><br>Phone <br><input type="text" size=10 MAXLENGTH=10 name="phone" value=<? echo $phone; ?> >
</td>
<tr>
<td align=center><br>Date <br><input type="text" size=6 MAXLENGTH=5 name="date" value=<? echo $date; ?> >
</td>
</table>
</form>
<form>
<?
print "FORM2 state ".$state."<br>";
print "FORM2 city ".$city."<br>";
print "FORM2 date ".$date."<br>";
print "FORM2 phone ".$phone."<br>";
?>
<input type='hidden' name='state' value=<?echo $state?>>
<input type='hidden' name='city' value=<?echo $city?>>
<input type='hidden' name='date' value=<?echo $date?>>
<input type='hidden' name='phone' value=<?echo $phone?>>
<input type='hidden' name='savebutton' value='1'>
<input type='submit' name='save' value='Save Data'>
</form>
<?
}
?>