473,396 Members | 2,109 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.

textbox data not available in post variable

nithinkolekar
I am trying to code a form that has multiple textbox without refershing page using ajax, then after each textbox threre will be link called add which POST call the other php called addnew.php.

In addnew.php data will we added to database(postgres). But I am geting problem while getting the post variable itself.For testing I added the alert in script.

this is my code for form (I will chage for multiple textbox once it works fine)

Expand|Select|Wrap|Line Numbers
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
  2. <html xml:lang="en" xmlns="http://www.w3.org/1999/xhtml" lang="en">
  3. <head>
  4.   <meta http-equiv="content-type" content="text/html; charset=UTF-8"/>
  5.   <title> - jsFiddle demo</title>
  6.   <script type='text/javascript' src='fade delete_files/jquery-1.4.2.js'></script>
  7.  
  8.   <link rel="stylesheet" type="text/css" href="fade delete_files/normalize.css"/>
  9.   <link rel="stylesheet" type="text/css" href="fade delete_files/result-light.css"/>
  10.  
  11.   <style type='text/css'>
  12.  
  13.   </style>
  14.  
  15.   <script type='text/javascript'>
  16.     //<![CDATA[
  17.     $(window).load(function() {
  18.         jQuery(document).ready(function() {
  19.  
  20.             jQuery('.add').live('click', function(event) {
  21.  
  22.                 //var da='da='+ $('#da').attr('value');
  23.                 //var da = 'test';
  24.                 var da = $('form#myform').serialize();
  25.                 alert(da);
  26.                 $.ajax({
  27.                     type: "POST",
  28.                     url: "addnew.php",
  29.                     data:da,
  30.                     success: function(data) {
  31.                         if (data === "ok") {
  32.                             $(this).parent().fadeOut();
  33.                             $('#results').html(data);
  34.                         }
  35.                         else {
  36.                             alert(data);
  37.                         }
  38.                     }
  39.  
  40.                 });
  41.             });
  42.  
  43.         });
  44.     });
  45.     //]]>
  46. </script>
  47. </head>
  48. <body>
  49.   <ul>
  50.     <li>One | <a href='#' class='add'>Delete</a></li>
  51.     <li>Two | <a href='#' class='add'>Delete</a></li>
  52.     <li>Three | <a href='#' class='add'>Delete</a></li>
  53.     <li>Four | <a href='#' class='add'>Delete</a></li>
  54.  
  55. </ul>
  56. <?php
  57.  
  58. for ($i=1;$i<2;++$i) {//currently only one textbox for testing purpose
  59.  
  60.      echo "<form name='myform' id='myform'>";
  61.      echo     "<input name='da' type='text' id='da' value='none'>";
  62.      echo     "<a href='#' class='add'>Add</a>";
  63.       echo "</form>";
  64. }
  65. ?>
  66. <div id="results"><div>
  67. </body>
  68.  
  69.  
  70. </html>
  71.  
  72.  
addnew.php code
Expand|Select|Wrap|Line Numbers
  1. <? php
  2.  if( isset($_POST['da']) ) 
  3.  {
  4.        echo (da);
  5.   }
  6. ?>
when page is rendered will have like this.

<textbox1 data> <add button>
<textbox1 data> <add button>
<textbox1 data> <add button>
...
<textbox10 data> <add button>

what I am trying is

1. Created each textbox and add button pair inside each form dynamically using for loop.
(for testing i created only one pair).Should I have form for every pair?
2. when add is clicked value within textbox (#da) should be send to addnew.php through ajax.

following code is displaying data correctly
Expand|Select|Wrap|Line Numbers
  1. alert(da);
but in addnew.php file I am not getting $_POST(['da']). Is that means data is not passed to the file or is there something wrong ajax code and finally can I have multiple form with same id. If not then how i can send the only one textbox data ie just before the add button when form is submitted.
Dec 11 '10 #1

✓ answered by Samishii23

Usually when a method isn't set in <form> tags, it defaults to get. Set the method to post in the form tag.

3 3079
Samishii23
246 100+
Usually when a method isn't set in <form> tags, it defaults to get. Set the method to post in the form tag.
Dec 11 '10 #2
johny10151981
1,059 1GB
your line 29 is completely wrong

only data is going

Expand|Select|Wrap|Line Numbers
  1. data:da,
  2.  
which mean only value but no variable name. Do this

Expand|Select|Wrap|Line Numbers
  1. data:"da="+da,
  2.  
you will get post data properly
Dec 12 '10 #3
@johny10151981
line 28 is enough
Expand|Select|Wrap|Line Numbers
  1. $('form#myform').serialize();
@Samishii23
works thanks
Dec 13 '10 #4

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

Similar topics

3
by: Thomas Hoheneder | last post by:
Hello, I use PHP 4.3.10 and want to deliver a post variable from a PHP page to itself. In my page mypage.php I have a hidden field named "dbaction" and a form button. When clicking the form...
4
by: Lee David | last post by:
I have a validation form that lets you enter your ID and password. Then I call the page again. This time the page script should check that it is a "recall" and check the entered data with the...
5
by: crowl | last post by:
I have a VB application sending data via post to an ASP page. The application sends two variable: id, txt If txt has the & sign in its string, it cause trouble. E.g.: id = 1 txt = "Hello &...
1
by: Jan Danielsson | last post by:
Hello all, How do I find out if a blocking socket has data available on it? I assume I could do something like this: tmp = self.read(1, socket.MSG_PEEK) if len(tmp) > 0: # Data available
1
by: Danial | last post by:
Hi, I am using asp.net 2 and i want to blank all textbox data of one form with (for each control) and i write following coding in button control, but it did not work. Dim ctl As Control ...
0
by: KCLA | last post by:
HELLO AND THANKS IN ADVANCE I am new to programming although my best mate is quite good and i have learnt a lot from him but i am now trying to understand the basic concept, however i cannot find...
1
by: unknown; | last post by:
hello i'm using a php script opening en parsing a url like www.OpenThisURL.com/site.php?a=aa&b=bb this url and website are not mine but i'm only using some information from the site. now...
2
by: DubSport | last post by:
I have created a datatable in a function, and it is populated with data. I want to call a new function from an ASP button, and write out some of the values in the datatable, using: string...
1
by: =?Utf-8?B?dmJTdHVkZW50?= | last post by:
Dear All, I have textbox in my form .. I enter the student name in the text e.x (vbstudent) I want to sign textbox data to array, each letter in one index. ex array(0)=v array(1)=b
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
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
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,...
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
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...
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
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...
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.