Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

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

Posted on 2012-04-12
6
Medium Priority
?
320 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 34

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 34

Accepted Solution

by:
Slick812 earned 1000 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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 

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

[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

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…
Originally, this post was published on Monitis Blog, you can check it here . In business circles, we sometimes hear that today is the “age of the customer.” And so it is. Thanks to the enormous advances over the past few years in consumer techno…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
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…
Suggested Courses

916 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