473,706 Members | 2,583 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

submit button and onchange.submit

3 New Member
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.s ubmit()

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 22278
a10392
3 New Member
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.su bmit()).
- 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."<b r>";
print "INDEX date ".$date."<b r>";
print "INDEX phone ".$phone."<br>" ;

if ($state=="")$st ate="stateA";//1;

if ($savebutton==' 1')print "Function to save";

$savebutton=0;
ask_data($state ,$city,$date,$p hone);



//############
//FUNCS.PHP
//#############


function ask_data($state ,$city,$date,$p hone)
{
$states=array(' stateA','stateB ');
$city1=array("S tateAcity1","St ateAcity2","Sta teAcity3");
$city2=array("S tateBcity1","St ateBcity2","Sta teBcity3");
?>

<table width="735" border="1" cellspacing="0" cellpadding="0" >
<tr>
<td align=center><b r>State&nbsp
<form method="POST" enctype='applic ation/x-www-form-urlencoded' style="word-spacing: 0; margin-top: 0; margin-bottom: 0" name="formstate " action="index.p hp">
<select name="state" onchange=formst ate.submit() >
<? for ($i=0;$i<sizeof ($states);$i++)
if ($state==$state s[$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=='state A') $citys=$city1;
else $citys=$city2;
?>
<select name="city" onchange=formst ate.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><b r>Phone&nbsp<br ><input type="text" size=10 MAXLENGTH=10 name="phone" value=<? echo $phone; ?> >
</td>
<tr>
<td align=center><b r>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."<b r>";
print "FORM2 date ".$date."<b r>";
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='savebutto n' value='1'>

<input type='submit' name='save' value='Save Data'>
</form>
<?
}
?>
Oct 2 '05 #2
rohypnol
54 New Member
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($_REQUE ST['submit_btn']))
{
if (isset($_REQUES T['user_opt']))
echo 'The option previously selected is: '.$_REQUEST['user_opt'];
?>

<form method="post" action="file.ph p" name="dumbform" >
<select name="user_opt" onchange="dumbf orm.submit()">
<option value="1">one</option>
<option value="2">two</option>
<option value="3">three </option>
</select>
<input type="submit" name="submit_bt n">
</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
2257
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 database with those textareas which were changed. Thus, each textarea has an onChange event which marks that box as changed. BUT! Some users report that, if they don't take their cursor out of
2
7042
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 and onChange handlers do some minor manipulation of form data (although they work on different form elements). If the onChange event fires, I need the form to be submitted. If the onClick event fires for a TR, I also need the form to be...
6
2748
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 fine.... except that the element MYBUTTON must exist as a hidden field.
5
3460
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 be submitted, but it isn't for some weird reason. However, after I press the ok button, it submits the form, and then the combo boxes start working normally. In IE, everything works fine. I appreciate any help. Thank you. <html>
2
1901
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 language="javascript"> function validatePage(){
2
4666
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 data to database. After each submit , i need to display the previous added details (with some checkboxes checked and some others unchecked ..) and one new row for next updation. Here i need to collect all values submitted in the php page. There i...
3
1435
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 city/state combinations, if the button is clicked the data is added to the database. Perhaps there is a better way to grow the number of city/state combinations while still retaining any text previously typed into the input boxes? Thanks for...
1
3513
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. There is a small bit of javascript which, when the 'onChange' event occurs, triggers a 'submit' which reloads the page and displays the stored values for that session using a session ID variable named, '$existingSessions'. Even though the form's...
14
75520
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" enctype="multipart/form-data" name="form1"> <select onchange="this.form.submit();" name="prod"> <option value="">Select product</option> <option value="12">abc</option>
0
8772
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8692
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9276
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
9038
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8982
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6607
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5934
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
3140
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2493
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.