473,396 Members | 1,875 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

submit button and onchange.submit

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, 1055 views)
Oct 1 '05 #1
2 22257
a10392
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
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

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

Similar topics

2
by: S Wickes | last post by:
I've become suspicious that the submit button does not count as an onChange event in some browsers. Here's why. I have a form with many textareas. After you click submit, I only update the...
2
by: Andy Goldstein | last post by:
I have a table where all the TRs have an onClick handler registered. One (and only one) of the rows has 2 text input boxes, where each textbox has an onChange handler registered. Both the onClick...
6
by: charlie_M | last post by:
I figured out via various help from this forum... EXAMPLE: onClick="document.forms.MYBUTTON.value='SIMPLE';document.forms.submit()" In my CGI I see "MYBUTTON" = "SIMPLE" and this works...
5
by: Pascal Batzli Jr | last post by:
Hello, I have a strange situation happening on the code below. When I first load the page, as I change any of the three combo boxes I have created, the onchange event is fired and the form should...
2
by: Gayathri | last post by:
Please find the pasted html, <html> <script language="JavaScript" src="cal.js"></script><!-- Date only with year scrolling --> </head> <BODY onLoad="showDetails()"> <script...
2
by: somaskarthic | last post by:
Hi In my php code , i dynamically created table rows on button click event. Each row contain 3 selectboxes, 7 checkboxes . On each click of these elements i need to submit the form and save the...
3
by: Greg Scharlemann | last post by:
I have some php code to handle the following form is submitted, but because there are two places the form submits I get an error. If the drop down changes, the php code will grow the number of...
1
by: rynato | last post by:
I ran into an interesting problem while working on a form: I have a drop down list (think <form><select><option>...) of 'open sessions' which a user can choose from to continue entering data....
14
by: white lightning | last post by:
How to have <select onchange="this.form.submit()"and also a Submit button on one form? I have something like this: <form action="<?php $_SERVER; ?>" method="post"...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.