Solved

how to pass the output of an ajax script...

Posted on 2012-04-12
6
262 Views
Last Modified: 2012-04-12
Hi, I have an application where I use a Ajax script to display a value in a form, the value is being displayed correctly. When I submit the form I need to pass this value using $_POST, how do I do this? Thanks for the help.

A
socDate.php
ajaxScript.txt
0
Comment
Question by:aej1973
  • 4
  • 2
6 Comments
 
LVL 33

Expert Comment

by:Slick812
ID: 37839265
greetings  aej1973, , , not sure about what to help you with, this could be done with javascript (a js post form function) or you could do this by changing a form hidden element value to the   xmlhttp.responseText   string value  (of course with out the </br>)

but you seem inexperienced with AJAX, so not sure what might suit you.

could you show us your form  DHTML, so maybe I could show you how to change a hidden form element value to the  $row['admit_date'] from ajax
0
 

Author Comment

by:aej1973
ID: 37839346
Hi Slick812, attached is the from that I am using.
Planner.php
0
 
LVL 33

Accepted Solution

by:
Slick812 earned 250 total points
ID: 37839662
OK, I looked at your code for the  planner.php and the  socDate.php   files.

First this is some code you can change in the planner.php  file -

you need to add a hidden element to the  newPatient   FORM, I  might suggest you add the hidden right after the FORM declaration-

<form name="newPatient" method="post" action="cellColor.php">
<input type="hidden" name="ajid" value="0">

Open in new window

the rest of the PHP and form inputs in the planner.php do NOT need to be changed as far as I can tell.


next you will need to change this hidden value in the Ajax showUser( ) function add this line right after the socDate change the inner HTML thing -

// You should have some error control for ajax so add -
if ((xmlhttp.responseText == "ERROR") || (xmlhttp.responseText == "")) {
    alert('Ajax ERROR - No Result');
    return;
    }
document.getElementById("socDate").innerHTML = xmlhttp.responseText+"<br>";
document.newPatient.ajid.value = xmlhttp.responseText; // add this line

Open in new window



Now for the  socDate.php  file

there are several things about this php file that are unsafe for MySQL

include "../common/connect.php";
$q = $_GET["q"];
// WARNING you must avoid SQL injection in AJAX
$q = mysql_real_escape_string($q);
$sql = "select admit_date from patient_newpatient where patient_id ='".$q."'";
$result = mysql_query($sql);
if (!$result) {
// not all selects will return results, you might also check for the number of rows returned
    echo 'ERROR';
    exit;
    }
$row=mysql_fetch_assoc($result);
///$result = mysql_query($sql);  second query is invalid

//Only send back the admit date, NO HTML <br>
echo $row['admit_date'];

Open in new window




I hope these suggestions help you, I can not try this in working PHP because I do not have your database,

the code above is untested code but should give you some code to help
0
Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

 

Author Comment

by:aej1973
ID: 37839714
Thank you Slick812, I will work on this and get back to you.

A
0
 

Author Comment

by:aej1973
ID: 37841134
Thanks a ton, works great!
0
 

Author Closing Comment

by:aej1973
ID: 37841136
Thank you.
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

Introduction A frequently asked question goes something like this:  "I am running a long process in the background and I want to alert my client when the process finishes.  How can I send a message to the browser?"  Unfortunately, the short answer …
These days socially coordinated efforts have turned into a critical requirement for enterprises.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

708 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now