By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,016 Members | 2,297 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,016 IT Pros & Developers. It's quick & easy.

submit button and onchange.submit

P: 3
Hi,

I'am triyng to create a form where i have 2 comboBox and 2 textbox, when the selection changes on the first combo , the content of second also changes. i have to use onchange=form.submit()

the problem is, i want to have a button to finish the selection and save all the data to a database, but if i have diferent forms, i will not get the last change on the text boxs, only th last change when i changed the combobox.

Using the same form how can i know if it was the button pressed or the combochange that executed the submit ??

here's an example

Could you help me

Thx
Attached Files
File Type: zip example.zip (1.2 KB, 1021 views)
Oct 1 '05 #1
Share this Question
Share on Google+
2 Replies


P: 3
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&nbsp
<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&nbsp<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&nbsp<br><input type="text" size=10 MAXLENGTH=10 name="phone" value=<? echo $phone; ?> >
</td>
<tr>
<td align=center><br>Date&nbsp<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>
<?
}
?>
Oct 2 '05 #2

rohypnol
P: 54
I didn't understand much of what you said and your code is a mess. Stop using short tags and put double quotes around parameter values. But getting to your question, which I hope I got right and I hope this is what you need:

*** FILE.PHP
[PHP]<?php
if (!isset($_REQUEST['submit_btn']))
{
if (isset($_REQUEST['user_opt']))
echo 'The option previously selected is: '.$_REQUEST['user_opt'];
?>

<form method="post" action="file.php" name="dumbform">
<select name="user_opt" onchange="dumbform.submit()">
<option value="1">one</option>
<option value="2">two</option>
<option value="3">three</option>
</select>
<input type="submit" name="submit_btn">
</form>

<?php
} else {
DoSomething();
?>

You have pressed the submit button.<br />
user_opt = <?php echo $_REQUEST['user_opt']; ?>

<?php
}
?>[/PHP]
Dec 6 '07 #3

Post your reply

Sign in to post your reply or Sign up for a free account.