Solved

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

Posted on 2012-04-12
6
272 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

This article discusses four methods for overlaying images in a container on a web page
This article discusses how to create an extensible mechanism for linked drop downs.
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

911 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

23 Experts available now in Live!

Get 1:1 Help Now