hi guys , - $("#patient_id").change(function(){
-
$.post("/diabetes/patient_detail_change.php",{ location:$("#location").val(),doctor:$("#doctor").val(),patient_id:$("#patient_id").val()} ,function(data){
-
alert(data);
-
//$("#patient_id").html(data);
-
});
-
});
i have written a code like this. It returns a array of value like Name => 'pradeep',Age=> '23'
i.e data is array
there are form fields like Name and Age. I need to take the values from the data and set it to each form fields how to do this.how to deal with arrays in jquery.
19 3735
i outputted the array its like
{"Patient_id":"R00020","Name":"admin","Age":"12"," Weight":"67","Gest_age":"2"}
i tried to iterate through it by using this code - $.each(data, function(key, value) {
-
alert(key + ': ' + value);
-
});
-
but its not working . Is anything wrong?
the only thing on my mind … debug by hand using Firebug and setting breakpoints.
when i am printing it ,its printing like 0 :P 1:a 2:t .its taking each letter as an array element.
no solution to this prob?
Ok I am trying to understand what you need. Basicly you have a form and you have array. You want to populate your form with values from this array? If so can you copy/paste your form?
i am getting the array in jquey in format
{"Patient_id":"R00020","Name":"admin","Age":"12 "," Weight":"67","Gest_age":"2"}
is this the rite format?
-
var my_var = {"Patient_id":"R00020","Name":"admin","Age":"12"," Weight":"67","Gest_age":"2"}
-
Yes you could do it that way
You might want to have a look here JSON
i use php for server side scripting . i use json to convert php array to jquery required format array and sent it back to jquery and tried to iterate but the iteration is not happening.
If you want to iterate through JSON -
var my_json = {"Patient_id":"R00020","Name":"admin","Age":"12"," Weight":"67","Gest_age":"2"};
-
$.each(my_json, function(i){alert(this)})
-
Or if you want to iterate through form elements: -
$(function(){
-
$("form > *").each(function(){alert(this.name)})
-
})
-
i will give this a try and let u know.
each of this key values is a form element like,Patient_id,Name,Age. how do i take these values from array and give the form elements these values.
i am posting the code for help
here the jquery is printing properly if my_json array is passed but if i pass data which i returned from php code its not printing properly -
$("#patient_id").change(function(){
-
$.post("/diabetes/patient_detail_change.php",{ location:$("#location").val(),doctor:$("#doctor").val(),patient_id:$("#patient_id").val()} ,function(data){
-
alert(data);
-
-
var my_json = {"Patient_id":"R00020","Name":"admin","Age":"12"," Weight":"67","Gest_age":"2"};
-
//alert(my_json);
-
$.each(my_json, function(i){alert(this)});
patient_detail_change.php - <?php
-
include_once('db.php');
-
$location = $_POST['location'];
-
$doctor = $_POST['doctor'];
-
$patient_id = $_POST['patient_id'];
-
if(($location != "") && ($doctor != "")){
-
$sql = "select Name,Age,Gest_age,Weight from rop_form where Location = '".$location."' and Doctor = '".$doctor."' and Patient_id = '".$patient_id."'";
-
$result = mysql_query($sql);
-
$myresult = "";
-
while($row = mysql_fetch_array($result))
-
{
-
$myresult['Patient_id'] = "R".$patient_id;
-
$myresult['Name'] = $row['Name'];
-
$myresult['Age'] = $row['Age'];
-
$myresult['Weight'] = $row['Weight'];
-
$myresult['Gest_age'] = $row['Gest_age'];
-
$myresult = json_encode($myresult);
-
}
-
}
-
else
-
{
-
$myresult .= "";
-
}
-
echo $myresult;
-
?>
-
hope ma code is clear enough!
-
$.post("/diabetes/patient_detail_change.php", function(json_data){alert(json_data);})
-
That should clear it up.
I didnt check your patient_detail_change.php at all but glanced over. You have variable $myresult that keeps changing type from string to array back to string. Even though that php is loosely typed language and will allow you to do things like that you should be avoiding it. Imagine you have 5000 lines of code and your variables keeps changing type like that. It would be very difficult to understand or to read code like that.
nope man it did not work :(
see the code
jquery code: - $("#patient_id").change(function(){
-
$.post("/diabetes/patient_detail_change.php",{ location:$("#location").val(),doctor:$("#doctor").val(),patient_id:$("#patient_id").val()} ,function(json_data){
-
-
alert(json_data);
-
-
$.each(json_data, function(key,value){
-
alert(key + ': ' + value);
-
if(key == 'Name'){ $("#name").val(value);}
-
if(key == 'Age'){ $("#age").val(value);}
-
if(key == 'Weight'){ $("#ropweight").val(value);}
-
if(key == 'Gest_age'){ $("#gest_age").val(value);}
-
-
});
-
-
});
-
});
the alert(json_data); line prints this
{"Patient_id":"R00008","Name":"","Age":"12","Weigh t":"67","Gest_age":"2"}
but the alert(key + ': ' + value); is printing like
0:{ 1:P 2:a and so on .
the php code is like this and as u pointed out i have corrected the variable and array issue -
<?php
-
include_once('db.php');
-
$location = $_POST['location'];
-
$doctor = $_POST['doctor'];
-
$patient_id = $_POST['patient_id'];
-
if(($location != "") && ($doctor != "")){
-
$sql = "select Name,Age,Gest_age,Weight from rop_form where Location = '".$location."' and Doctor = '".$doctor."' and Patient_id = '".$patient_id."'";
-
$result = mysql_query($sql);
-
$myresult = "";
-
while($row = mysql_fetch_array($result))
-
{
-
$myresult1['Patient_id'] = 'R'.$patient_id;
-
$myresult1['Name'] = $row['Name'];
-
$myresult1['Age'] = $row['Age'];
-
$myresult1['Weight'] = $row['Weight'];
-
$myresult1['Gest_age'] = $row['Gest_age'];
-
}
-
$myresult = json_encode($myresult1);
-
}
-
else
-
{
-
$myresult .= "";
-
}
-
echo $myresult;
-
?>
-
$.getJSON("/diabetes/patient_detail_change.php", function(json_data){ $.each(json_data, function(i){alert(i + ":" + this)})})
-
Hope this works
nope.its not printing anything at all now after adding getJSON
$_GET instead of $_POST.
More info about getJSON here
hii i had to use something like -
$("#patient_id").change(function(){
-
$("#name").val('');
-
$("#Age").val('');
-
$("#ropweight").val('');
-
$("#Gest_age").val('');
-
-
$.getJSON (
-
"/diabetes/patient_detail_change.php",
-
{
-
location:$("#location").val(),
-
doctor:$("#doctor").val(),
-
patient_id:$("#patient_id").val()
-
},
-
-
function (json_data){
-
-
if (json_data.Name) { $("#name").val(json_data.Name);}
-
if (json_data.Age) { $("#age").val(json_data.Age);}
-
if (json_data.Weight) { $("#ropweight").val(json_data.Weight);}
-
if (json_data.Gest_age) { $("#gest_age").val(json_data.Gest_age);}
-
},
-
"Json"
-
);
-
});
and $_GET in the php file. :).thanks for all the help!
Sign in to post your reply or Sign up for a free account.
Similar topics
by: liketofindoutwhy |
last post by:
I am learning more and more Prototype and Script.aculo.us and got the
Bungee book... and wonder if I should get some books on jQuery (jQuery
in Action, and Learning jQuery) and start learning about...
|
by: RobG |
last post by:
Do some of the regulars here need to re-think their (sometimes
strident) opposition to libraries? Both Microsoft and Nokia have
announced support for jQuery.
It seems to have gained quite a bit...
|
by: souporpower |
last post by:
Hello All
I am trying to activate a link using Jquery. Here is my code;
<html>
<head>
<script type="text/javascript" src="../../resources/js/
jquery-1.2.6.js"</script>
<script...
|
by: jrod11 |
last post by:
hi,
I found a jquery html table sorting code i have implemented. I am trying to figure out how to edit how many colums there are, but every time i remove code that I think controls how many colums...
|
by: amskape |
last post by:
hi Friends,
I need to Upload some files in a Listing , by clicking
corresponding Upload link, then a popup window will
come with Browse option as Shown in attachment File.
My actual need is...
|
by: Tj Jurado |
last post by:
Hi guys,
I am new to this and need a little help.
I have an html block to be rotated and placed in an array via php as well as printed as an xml format then. Without refreshing the page, the...
|
by: BaseballGraphs |
last post by:
Hello,
I am trying to format the output of my data with the autocomplete function from jQuery. So far, I've been able to build the entire process, however, I want to limit the information I show...
|
by: BaseballGraphs |
last post by:
Hello,
I am making use of jQuery's .autocomplete plugin, and I would appreciate some assistance formating the results that show up in the dropdown menu that populates when text is written into the...
|
by: empiresolutions |
last post by:
I'm building a navigation that is built heavily on jQuery. I have it working as needed except that when mousing over links to quickly it spikes the processor and the navigation hangs. By hangs i mean...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
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...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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...
|
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,...
|
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...
|
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: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new...
| |