473,321 Members | 1,669 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,321 software developers and data experts.

posting html form in ajax

hi,
i want to post an html form on the click of a button to an ajax function,this ajax function will pass this fom object to a php page,where i want to fetch all the values entered by user in the form.

can anyone help me to do this,as im not able to pass the whole form and access the form values in php page.

thank you.
Mar 22 '07 #1
10 1743
ak1dnar
1,584 Expert 1GB
Where is the HTML form ? and Ajax script so far you have completed.
Mar 22 '07 #2
i did not understand your question clearly.please can u be bit more clear about what u want to know.

thank you.
Mar 22 '07 #3
ak1dnar
1,584 Expert 1GB
i did not understand your question clearly.please can u be bit more clear about what u want to know.

thank you.
I need your HTML form and JS script. Please post it here.
Mar 22 '07 #4
this is my html code:
[HTML]<form name="frminfo" action="<?php $_SERVER['PHP_SELF']?>" method="post">
<table width="85%" border="0" align="center">
<tr>
<td valign="top" class="desc">
State <font class="red">*</font>
</td>
<td valign="top" colspan="3">
<select name="selstate" onchange="showCity(this.value);" class="txtsty">
<option value="">Select State</option>
<option value="1">Maharashtra</option>
<option value="2">Delhi</option>
<option value="3">Gujarat</option>
<option value="4">Punjab</option>
</select>
</td>
</tr>
<tr>
<td valign="top" class="desc">
City <font class="red">*</font>
</td>
<td valign="top">
<div id="divcity"></div>
</td>
<td valign="top" colspan="2">
<input type="button" name="btncity" value="Add City" onclick="javascript:openPop(550,150)" class="btn">
</td>
</tr>
<tr>
<td valign="top" class="desc">
School <font class="red">*</font>
</td>
<td valign="top">
<div id="divschool"></div>
</td>
<td valign="top" colspan="2">
<input type="button" class="btn" name="btnschool" value="Add Institute" onclick="return valschool();">
</td>
</tr>

<tr>
<td valign="top" class="desc">
Contact Person Met<font class="red">*</font>
</td>
<td valign="top">
<input type="text" name="txt1">
</td>
</tr>

<tr>
<td valign="top" align="left" class="desc">
Remarks <font class="red"></font>
</td>
<td valign="top">
<textarea name="remarks" maxlength="350" rows="5" cols="25" class="txtsty"></textarea>
</td>
</tr>
<tr>
<td valign="top" class="desc">
Call Analysis <font class="red">*</font>
</td>
<td valign="top" colspan="2">
<select name="scall" class="txtsty">
<option value="">Select Call Analysis</option>
<option value="1">First Call(Tele)</option>
<option value="2">Follow up call(Tele)</option>
<option value="3">First call (Field)</option>
<option value="1">Follow up call(Field)</option>
</select>
</td>
</tr>

<tr>
<td valign="top" class="desc">
School Status <font class="red">*</font>
</td>
<td valign="top">
<select name="sel1">
<option value="">Select</option>
<option value="1">Interested</option>
<option value="2">Uninterested</option>
<option value="3">Undecided</option>
</select>
</td>
</tr>
<tr>
<td valign="top" align="right" class="desc">
Next Contact Date<font class="red"></font>
</td>
<td valign="top" colspan="3">
<INPUT TYPE="text" NAME="sdate" VALUE="<?php echo $sdate;?>" SIZE="10" maxlength="10" readonly class="txtsty">
<A HREF="#" onClick="cal.select(document.forms['frminfo'].sdate,'anchor1','dd/MM/yyyy'); return false;"
NAME="anchor1" ID="anchor1">select</A>
</td>
</tr>
<tr>
<td valign="top" colspan="4" align="center">
<input type="button" name="btn1" class="btn" onclick="addDetails(this.form);" value=" Save Details ">
</td>
<td>
<div id="divtest"></div>
</td>
</tr>
</table>
</form>[/HTML]

button : btn1 is the button on the click of which i call function addDetails(this.form);

and the ajax function addDetails is

Expand|Select|Wrap|Line Numbers
  1. function addDetails(form1)
  2.     xmlHttp=GetXmlHttpObject();
  3.     if (xmlHttp==null)
  4.     {
  5.         alert ("Your browser does not support AJAX!");
  6.         return;
  7.     } 
  8.  
  9.     alert(form1);
  10.     var url="ajax_add.php";
  11.     xmlHttp.onreadystatechange=stateChanged4;
  12.     xmlHttp.open("POST",url,true);
  13.     xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
  14.     //xmlHttp.setRequestHeader("Content-length",form1.length);
  15.     //xmlHttp.setRequestHeader("Connection", "close");
  16.     xmlHttp.send(form1);
  17. }
  18. function stateChanged4() 
  19.     if (xmlHttp.readyState==4)
  20.     {
  21.         document.getElementById("divtest").innerHTML=xmlHttp.responseText;
  22.     }
  23. }
this is my php code where i need to fetch the values from html form:

[PHP] $txtdate=$_POST["txtdate"];
$date=$txtdate;
$sid=$_POST["selstate"];
$cid=$_POST["selcity"];
$school=$_POST["school"];
$svid=$_POST["svisit"];
$cperson=$_POST["cperson"];
$scid=$_POST["scall"];
$remarks=$_POST["remarks"];
$min_to = $_POST["minto"];
$time_to = $_POST["timeto"];
$min_from = $_POST["minfrom"];
$time_from = $_POST["timefrom"];
$sdate=$_POST["sdate"];
$status=$_POST['status'];



$fromdate1=array();
$fromdate1 = explode("/",$date);
$dat=$fromdate1[0];
$mon=$fromdate1[1];
$year=$fromdate1[2];
$date= $year."-".$mon."-".$dat;

$currentdatetime=date("Y-m-d H:i:s");

$insertquery="insert into daily_transaction(zid,uid,date_user,date_schedule, sid,cid,ssid,institute_id,status_id,contact_person ,call_id,remarks,time_from,min_from ,time_to,min_to,date)values('$zid','$userid','$dat e','$sdate','$sid','$cid','$status','$school','$sv id','$cperson', '$scid','".addslashes($remarks)."','$time_from','$ min_from','$time_to','$min_to','$currentdatetime') ";

$result = mysql_query($insertquery);[/PHP]




javascript error im getting is "INCORRECT PARAMETER PASSED"


thanx.
Mar 22 '07 #5
dmjpro
2,476 2GB
i m also waiting for that .....
Mar 22 '07 #6
please can anyone help me for the same.

thanx.
Mar 22 '07 #7
acoder
16,027 Expert Mod 8TB
You have to send parameters, not form1, e.g.
Expand|Select|Wrap|Line Numbers
  1. "txtdate="+form1.txtdate.value+"&seldate="+form1.seldate.value+...
For Firefox, if you're not sending back a valid XML response, override the mimetype.
Mar 22 '07 #8
dmjpro
2,476 2GB
ok .... i understand ... but can't i send it via POST method ????

plz help .... thanxxx in advance
Mar 22 '07 #9
acoder
16,027 Expert Mod 8TB
That is via the post method. If it was a GET request, the send parameter would be null.
Mar 22 '07 #10
ak1dnar
1,584 Expert 1GB
Expand|Select|Wrap|Line Numbers
  1. function addDetails()
  2.     xmlHttp=GetXmlHttpObject();
  3.     if (xmlHttp==null)
  4.     {
  5.         alert ("Your browser does not support AJAX!");
  6.         return;
  7.     } 
  8.     var some_var = form1.your_form_element.value;
  9.     var another_var = form1.another_form_element.value;
  10.     var url="ajax_add.php";
  11.     xmlHttp.open("POST",url);
  12.     xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
  13.     xmlHttp.onreadystatechange=stateChanged4;
  14.     xmlHttp.send('var1='+some_var+'&var2='+another_var);
  15.     /*PHP side use 
  16.     $varname1 = $_POST['var1'];
  17.     $varname2 = $_POST['var2'];
  18.     */
  19.  
  20. }
  21. function stateChanged4() 
  22.     if (xmlHttp.readyState==4)
  23.     {
  24.         document.getElementById("divtest").innerHTML=xmlHttp.responseText;
  25.     }
  26. }
Mar 22 '07 #11

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

Similar topics

6
by: bbcrock | last post by:
Unfortunately my users are demanding this functionality: They are on a form. Click on an "add" button. An html window pops up. They add a new item that is saved to the database. The window...
2
by: pamelafluente | last post by:
Hi dears, I have a plain HTML page. I want to render it a little interactive. I was thinking to add to it 1 script and events to the elements I want to make interactive. Then, I need to...
7
by: pamelafluente | last post by:
The precious input given by Laurent, Martin, Benjamin about XMLHttpRequest in Javascript, has made me think that perhaps I could improve what I am currently doing by using Ajax. Let's make it...
4
by: d3vkit | last post by:
I have a form on my page, and some javascript which uses ajax to submit the form, and then opens the new page in a div using ajax so there is no refresh. This works fine. But the problem is this: all...
1
by: eunever32 | last post by:
Hi I have a struts (1.1) form <html:form <html:text <html:text ...
3
by: dmorand | last post by:
I've looked far and wide around the internet trying to find a decent tutorial on how to start using ajax to control my form posting. I'd like to have it so my users don't have to go to a new...
9
by: Tim Johnson | last post by:
I'm an experienced web/CGI programmer, but new to ajax. I'd like to review some examples of how to post data from a form to server using AJAX. I have already created some examples successfully...
14
by: Tom Cole | last post by:
I have a rather complicated business application that uses Ajax. Part of this form requires uploading documents, which I cannot do using Ajax, so I post the form to an IFrame. This part works just...
10
dj12345
by: dj12345 | last post by:
Hi, (Asp.net + Ajax) I am creating a page which will fetch data from server without postbak of a page.. I have 2 controls on this page TextBox and Lable. I have assigned TextBoxWatermark...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

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.