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

having a problem submitting forms via ajax

27
Hi guys,

I have some text inputs which I would like to submit to a database via PHP using ajax. What i want to do is when the submit button is pressed I want the forms to disappear and on their place to show up a message saying ...."thanks for submitting you data"... how can I do that. any help pls?
so i have
Expand|Select|Wrap|Line Numbers
  1. <form...><input.../>
  2. <input>
  3. <input type="submit">
  4. </form>
after pressing on submit I want only the text form out of the whole page to disappear and the rest to remain and on their place to show up a message echo-ed by php.
Aug 19 '07 #1
7 1393
pbmods
5,821 Expert 4TB
Bettor, please use CODE tags when posting source code. See the REPLY GUIDELINES on the right side of the page next time you post.
Aug 19 '07 #2
bettor
27
OK sorry for the mistake. I need help replacing forms with a successful submittion message using ajax. any help?
Aug 20 '07 #3
ak1dnar
1,584 Expert 1GB
Hi guys,

I have some text inputs which I would like to submit to a database via PHP using ajax. What i want to do is when the submit button is pressed I want the forms to disappear and on their place to show up a message saying ...."thanks for submitting you data"... how can I do that. any help pls?
so i have
Expand|Select|Wrap|Line Numbers
  1. <form...><input.../>
  2. <input>
  3. <input type="submit">
  4. </form>
after pressing on submit I want only the text form out of the whole page to disappear and the rest to remain and on their place to show up a message echo-ed by php.
Insert your Form inside a <div id="formName"> and On submit set the visibility property to hidden for it.

Then Remaining Task could Handle by Ajax, ResponseTexts.
Aug 20 '07 #4
bettor
27
If I am using the following ajax function
Expand|Select|Wrap|Line Numbers
  1. <script type="text/javascript">
  2. function ajaxFunction()
  3.   {
  4.   var xmlHttp;
  5.   try
  6.     {
  7.     // Firefox, Opera 8.0+, Safari
  8.     xmlHttp=new XMLHttpRequest();
  9.     }
  10.   catch (e)
  11.     {
  12.     // Internet Explorer
  13.     try
  14.       {
  15.       xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
  16.       }
  17.     catch (e)
  18.       {
  19.       try
  20.         {
  21.         xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
  22.         }
  23.       catch (e)
  24.         {
  25.         alert("Your browser does not support AJAX!");
  26.         return false;
  27.         }
  28.       }
  29.     }
  30.     xmlHttp.onreadystatechange=function()
  31.       {
  32.       if(xmlHttp.readyState==4)
  33.         {
  34.         document.myForm.time.value=xmlHttp.responseText;
  35.         }
  36.       }
  37.     xmlHttp.open("GET","time.asp",true);
  38.     xmlHttp.send(null);
  39.   }
  40. </script>
how should I change
Expand|Select|Wrap|Line Numbers
  1. document.myForm.time.value=xmlHttp.responseText;
to address the div id=someid
Aug 21 '07 #5
ak1dnar
1,584 Expert 1GB
Exelent, at least you are trying http://www.w3schools.com.But I am Not recomending the GET method to submit your Form data. How about POST.[BTW you can use GET also].


  • Create a Form by putting id for each form element in the form.
  • Onsubmit the pass call for javascript function to collect the Submitted data from the form.
  • On the Page where you have created your Form create empty div.
    Expand|Select|Wrap|Line Numbers
    1.  <div id="status_msg"></div>
    2.  
    3.  
    4.  
    5.  
    6.  
    7.  
    8.  
    9.  
  • If you are familiar with readyState property of t XMLHttpRequest you can write down some messages to the status_msg div while the process is going on and and also you can hide your Form at the same time.
P.S. I can Send you the code but how about learning it step by step your self. I think you are not in a hurry.
Aug 22 '07 #6
dmjpro
2,476 2GB
Exelent, at least you are trying http://www.w3schools.com.But I am Not recomending the GET method to submit your Form data. How about POST.[BTW you can use GET also].


  • Create a Form by putting id for each form element in the form.
  • Onsubmit the pass call for javascript function to collect the Submitted data from the form.
  • On the Page where you have created your Form create empty div.
    Expand|Select|Wrap|Line Numbers
    1.  <div id="status_msg"></div>
    2.  
    3.  
    4.  
    5.  
    6.  
    7.  
    8.  
    9.  
  • If you are familiar with readyState property of t XMLHttpRequest you can write down some messages to the status_msg div while the process is going on and and also you can hide your Form at the same time.
P.S. I can Send you the code but how about learning it step by step your self. I think you are not in a hurry.

Ajaxrand is right.
It is better to learn it from yourself instead of taking the help from the beginning.
And one thing you have not pass the parameters which you want to submit.
Follow dis code it may help you to do it.

Expand|Select|Wrap|Line Numbers
  1. if(XMLHttp.readyState==4 && XMLHttp.status==200)
  2. {
  3. document.write(XMLHttp.responseText);
  4. }
  5. else{alert("There is something error with the target page");}
  6.  
Best of luck with your try.

Kind regards,
Dmjpro.
Aug 22 '07 #7
pbmods
5,821 Expert 4TB
Heya, Bettor.

Thanks for using CODE tags! Did you know that you can specify a language for your CODE tags to make your source code easier to read (and therefore make it more likely that our Experts will post solutions)?

You will still need to use [/code] to close your code blocks, regardless of the language, but you can the use one of these tags to open your code block:

[code=html]
[code=javascript]
[code=php]

and so on.

Thanks!

MODERATOR
Aug 22 '07 #8

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

Similar topics

1
by: Richard Dixson | last post by:
I have code that calls document.myFormName.submit() to submit a form automatically via JavaScript. This works just fine. However, if there is a button (or other form field element) on the form...
2
by: sandipm | last post by:
Hi all, I am facing problem with updating form element using javascript in MOZILLA Details are as follows. I have a div containing form element. on submit , i am submitting the form using...
3
by: Alok yadav | last post by:
I have an open IP and on that IP our main application is hosted. it uses ajax. in web.config file i have register ajax handlers. there are also other sites or project on that IP. now my problem is...
1
by: monudjn | last post by:
Hi I am implementing ajax in portal. Using ajax i am able to updating the content of portlets asynchronously. However i am facing a problem The Problem: While submitting the form i am getting...
5
by: Advo | last post by:
Basically, im redesigning a form page on our website. Currently the user submits the form, it does a few javascript checks and either submits to the "processstuff.php" page, or gives the user a...
14
by: javelin | last post by:
I need to fire off some server side code, but I don't want to submit the page I'm on. I know that's not technically possible (without something like AJAX, maybe?). What I thought might work is to...
4
by: paratge | last post by:
Hi, I'm updating one form in an iframe, with another in a main page. That works fine, th probliem is how to submit two forms with one click. For now i get an error "permission denied" how can...
2
by: K. | last post by:
Hi! I have problem with Firefox. I have such code: <? $xml = "<?xml version='1.0' encoding='utf-8' ?>"; $xml.="<table>"; $xml.="<tr><td colspan=\"5\"> <input type=\"hidden\"...
2
by: shivendravikramsingh | last post by:
hi friends, i m using a ajax function for retrieving some values from a database table,and display the values in required field,my prob is that the ajax function i m using is working f9 once,but if...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
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
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...

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.