473,804 Members | 3,074 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Submit the result of a query to the second form with no click

3 New Member
Hello,

I have two forms written mainly in php. Here how it functions currently:

- First form has two submit buttons.
- First submit button is a search button that submits a value of an input field that activates a database query and get the result
- I control the length of the entered text with Java Script in the input field and activate the query without clicking the search button when a certain length is achieved
- second submit button submits the result to the second form as an input field on the same page.

Now, what I would like to do is the following:

- Just send the result of the query to the second form without clicking the second submit button in the first form.

So:
- Control the length of the text entered in the input field (which I already do with Javascript)
- When the length equals to certain value activate the database query (which I already do with php)
- When the result is found submit the result to the second form without clicking any other buttons (which I don't know how to do)

I know it might be better to include some bit of code but even I tried to clean it is still too long to include here.

I would appreciate any hint.

huseyin
Mar 25 '08 #1
5 2068
hsriat
1,654 Recognized Expert Top Contributor
Hello,

I have two forms written mainly in php. Here how it functions currently:

- First form has two submit buttons.
- First submit button is a search button that submits a value of an input field that activates a database query and get the result
- I control the length of the entered text with Java Script in the input field and activate the query without clicking the search button when a certain length is achieved
- second submit button submits the result to the second form as an input field on the same page.

Now, what I would like to do is the following:

- Just send the result of the query to the second form without clicking the second submit button in the first form.

So:
- Control the length of the text entered in the input field (which I already do with Javascript)
- When the length equals to certain value activate the database query (which I already do with php)
- When the result is found submit the result to the second form without clicking any other buttons (which I don't know how to do)

I know it might be better to include some bit of code but even I tried to clean it is still too long to include here.

I would appreciate any hint.

huseyin
Its a unique case. Post you code here.
Mar 25 '08 #2
acoder
16,027 Recognized Expert Moderator MVP
Now, what I would like to do is the following:

- Just send the result of the query to the second form without clicking the second submit button in the first form.
If you can send the result to the first form, the second form should be easy. Get the response from the Ajax script and set the field(s) in the second form instead of the first.
Mar 26 '08 #3
huseyin
3 New Member
Thanks for replies. One thing is that I am not using Ajax even, I never attempted to use it. I have to use php+javascript at the moment unless you really insist that Ajax is the only solution :) In that case I have to learn yet another tool.

I will clean the code and post it here a.s.a.p.

huseyin
Mar 27 '08 #4
huseyin
3 New Member
I think I managed to clean the code a little bit and made it readable. I hope I didn't remove an important part by mistake :)

I have added some comment lines to make it somewhat more clear.

Once more, thanks for the help.

Here is the listing:

Expand|Select|Wrap|Line Numbers
  1. <script type="text/javascript">
  2. // check the number of digits entered in the search box
  3. function check()
  4. {
  5.   var letters = document.additem.item_search.value.length +1;
  6.   if (letters <= 6){
  7.     document.additem.item_search.focus();
  8.   } else {
  9.     document.additem.submit();
  10.     document.additem.addName.focus();
  11.   }
  12. }
  13. function check1()
  14. {
  15.   document.additem.addName.focus();
  16. }
  17. function check2()
  18. {
  19.   document.additem.addName.submit();
  20. }
  21. function formSubmit()
  22. {
  23.   document.additem.addName.submit();
  24. }
  25. function redirectOutput(add_name) {
  26.   var w = window.open('about:blank','Popup_Window','toolbar=no,location=no,directories=no,status=no,menubar=no,sc rollbars=no,resizable=no,copyhistory=no,width=700,height=550,top=20,left=500');
  27.   document.add_name.target = 'Popup_Window';
  28.   return true;
  29. }
  30. </Script>
  31. </head>
  32. <body>
  33. <?php
  34.   if(isset($_POST['addName'])){
  35.     $items_to_add=array();
  36.     $items_to_add=$_POST['id'];
  37.     $name_to_add=$_POST['name'];
  38.     $quantity_to_add=$_POST['quantity'];
  39.  
  40.     for($k=0;$k<count($items_to_add);$k++){
  41.       $_SESSION['items_in'][]=$items_to_add[$k].' '.$name_to_add . ' ' . $quantity_to_add;
  42.     }
  43.   }
  44. // posts to itself (this files name is additem.php)
  45.   echo "<form name='additem' method='POST' action='additem.php' onSubmit='formSubmit()'>
  46.      <table>
  47.      <tr>
  48.      <td>";
  49. // If something is entered in the search box do the search
  50. // This search is activated either by clicking the 'Go' button
  51. // or by pushing enter or when the entered character size equals to 6
  52.   if(isset($_POST['item_search'])  and $_POST['item_search']!=''){
  53.     $search=$_POST['item_search'];
  54.     $query="SELECT something FROM somewhere WHERE condition";
  55.   }
  56.  
  57.   $result=mysql_query($query,$dbf_osc->conn) or die(mysql_error());
  58.   $num_rows = mysql_num_rows($result);
  59. //This is the Search box and Go button
  60.   echo "<td>
  61.     <input type='text' id='item_search' name='item_search' MAXLENGTH='6' onKeyUp='(check() && check1())'>
  62.     <input type='submit' value='Go' id='item_go' name='item_go'></td>";
  63.   echo "<td><select name='items[]' size='1'>\n";
  64.  
  65. // If there is only one result add it automatically to the second form
  66. // (this is where I exactly fail)
  67. // Otherwise show the found items as a select box
  68.   if($num_rows==1){
  69.     $row=mysql_fetch_assoc($result);
  70.     $id=$row['id'];
  71.     $name=$row['name'];
  72.     $option_value=$id . ' ' . $name;
  73.     $display_item="$row[name]";
  74.     echo "<option selected value='".$option_value."'>".$display_item."</option>\n";
  75. // I thought this would do, but doesn't
  76.     echo "<script type=\"text/javascript\">
  77.       document.additem.addName.submit();
  78.           </Script>";
  79.   }
  80.   } else {
  81.     while($row=mysql_fetch_assoc($item_result)){
  82.       $id=$row['id'];
  83.       $name=$row['name'];
  84.       $option_value=$id . ' ' . $name;
  85.       $display_item="$row[name]";
  86.       echo "<option value='".$option_value."'>".$display_item."</option>\n";
  87.     }
  88.   }
  89.   echo "</select></td>";
  90. // This is the addname submit button
  91. // which submits the result of the search to the second form
  92.   echo"
  93.     <td><input type='submit' value='Add Name' id='addName' name='addName'></td>
  94.     </tr>
  95.     </table></form><br>
  96.     <script language=\"JavaScript\">
  97.     document.forms[0].elements[1].focus();
  98.       </script>";
  99. // Check if anything added to the second form
  100. // if so show the items
  101.   if(empty($_SESSION['items_in'])){
  102.     echo "<center><h3>&nbsp;</h3></center>";
  103.   }
  104.  
  105.   if(isset($_SESSION['items_in'])){
  106.     $num_items=count($_SESSION['items_in']);
  107.     $temp_item_name='';
  108.     $temp_item_id='';
  109.     $item_info=array();
  110.  
  111. // The second form is used to add some details about the search result
  112. // i.e. I search for a name with a given number and in this form
  113. // I add some quantity next to the name then generate a list of names
  114. // Finally i submit the generated list to the next screen
  115.     echo "<form name='add_name' action='list.php' method='POST' onSubmit='redirectOutput(this)'>
  116.     ";
  117.     echo "<table>
  118.       <tr>
  119.       <th>Id</th>
  120.       <th>Name</th>
  121.       <th>Quantity</th>
  122.       </tr>";
  123. // In fact at this point I get the Id from the previous form and
  124. // perform another search with the Id and pull the quantity from the database
  125. // if it is set earlier. To keep it short I skipped that query part
  126.       for($k=0;$k<$num_items;$k++){
  127.         $item_info=explode(' ',$_SESSION['items_in'][$k]);
  128.         $temp_id=$item_info[0];
  129.         $temp_name=$item_info[1];
  130.         $temp_quantity=$item_info[2];
  131.         echo "<tr>
  132.           <td>$temp_id</td>
  133.           <td>$temp_name</td>
  134.           <td><input type=text name='quantity$k' value='$temp_quantity' size='3'></td>
  135.           </tr>
  136.           <input type='hidden' name='item_id[$k]' value='$temp_id'>
  137.           <input type=hidden name='name[$k]' value='$temp_name'>
  138.           <input type=hidden name='quantity[$k]' value='$temp_quantity'>";
  139.       }
  140.   }
  141.  
  142.   echo "</table>";
  143. // The following submit gets the generated list and submits to the next screen
  144.   echo "<table>
  145.     <tr>
  146.     <td><input type='submit' name='AddNames' id='AddNames' value='List'>
  147.     </td>
  148.     </form>
  149.     </tr>
  150.     </table>";
  151. }
  152. $dbf->closeDBlink();
  153. ?>
  154.     </body>
  155.     </html>
  156.  
Mar 27 '08 #5
hsriat
1,654 Recognized Expert Top Contributor
You need to redesign the algorithm.

Use something like this:
Expand|Select|Wrap|Line Numbers
  1. <?php
  2. //FILE NAME : additem.php
  3.  
  4. if (submit_of_form1_pressed)
  5. {
  6.     get_the_search_from_the_db();
  7.     if (only_one_record present) 
  8.     {
  9.         display_the_result_for_that_one_record();
  10.         OR
  11.         redirect_to_the_second_form_action();
  12.         //eg..
  13.         header("Location:abc.php?q=aaa");
  14.     }
  15.     else
  16.     {
  17.         display_the_second_form();
  18.     }
  19. elseif (submit_of_form2_pressed)
  20. {
  21.     display_the_results_of_second_form();
  22.     OR
  23.     redirect_to_the_second_form_action();
  24.     //eg..
  25.     header("Location:abc.php?q=aaa");
  26. }
  27. else
  28. {
  29.     display_the_first_form();
  30. }
  31. ?>
But I'll still recommend to use Ajax to make it better.
Mar 27 '08 #6

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

Similar topics

5
12412
by: lsarg | last post by:
i've been trying forever to figure out a way to use a regular text link in place of a submit button at the bottom of this. can't get it. i'm just starting to learn php, so i'm stuck. any help at all would be amazing. <?php # Script 12.7 - login.php // This is the login page for the site. // Include the configuration file for error management and such.
15
28963
by: Mattia | last post by:
Hi! I have a <form> that can be submitted thruogh three buttons and I need to tell witch one was pressed when the form was submitted. I now do it with 3 <input type="submit" name="..." value="..."> with <input type="submit" ...> the only name-value values submitted (pushed into the query string) is the one of the submit button that was pushed (if you have many of them). Ex:
10
19363
by: Gregory A Greenman | last post by:
I'm trying to write a program in vb.net to automate filling out a series of forms on a website. There are three forms I need to fill out in sequence. The first one is urlencoded. My program is able to fill that one out just fine. The second form is multipart/form-data. Unfortunately, I haven't been able to fill that out in a way that makes the server happy. I set up a copy of this form at my web site so that I could see exactly what a...
4
5486
by: houstoncity2004 | last post by:
Hi, I need help to JavaScript. I am new to this, and am trying to the page online ASAP. I have two submit buttons on one form, and each button will have to do different things. I named both button "but1". The first button has the value "Continue", the second button has the value "new page". If someone click on the button with the value "Continue", I need to check if certain information has been filled in before proceeding, and if...
2
1903
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(){
5
4343
by: ningjun.wang | last post by:
How can I submit a form to multiple web sites when user click the submit button? Something like the following: myform.action = url_of_server1; myform.submit(); myform.action = url_of_server2; myform.submit(); The above code only submit form to url_of_server1. The second submit is ignored. Is there any trick to make it works? For example is it
1
2646
by: ansc1 | last post by:
Hello, I'm new to using php coding. I need help with the following: 1. There is a submit button on the form and is saves information to my database. After clicking on "Save Measurement" it redirects me to another page in my site. What I would like to do is change what page directs it to. Currently the submit button redirects me to page /measure/men_measure. I would like to be able to change this. Please see below my page below:...
2
2748
by: sakat | last post by:
<?php $dbhost = 'unix.lsbu.ac.uk'; $dbuser = 'lrc3'; $dbpass = 'dietdft_'; $dbname = 'lrc3'; // This is an example open a db $conn = mysql_connect($dbhost, $dbuser, $dbpass) or die ('Error connecting to mysql'); mysql_select_db($dbname);
2
1931
by: sbettadpur | last post by:
Hi everybody, Hi iam strugling with more than one submit buttons with in one form here is my code <form method="post" action="Offer.php" name='issueFrm' onSubmit="return fullOfferfields();"> OFFER <input type=image src="amarok_rewind.png " title="rewind" > <input type=image src="amarok_back.png" title="back"> <input type="text" size=3 name='txt'>&nbsp;<input type=image src="amarok_next.png " title="next" >&nbsp;<input type=image...
0
10558
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...
0
10318
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10302
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
10069
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...
0
9130
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7608
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
6844
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();...
2
3802
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2975
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.