Hi, I'm somewhat new to jQuery/JavaScript, so any help would be greatly appreciated. I have a few textboxes that need to be populated when a user clicks a hot spot on an image map. Each hot spot has an alt tag representing the ID number of the object I need to retrieve from a database. To retrieve the info from the DB, I have a small PHP script that is called with jQuery's .post() function, something to the effect of: JavaScript Syntax (Toggle Plain Text) 1. $.post($('#myForm').attr('action'),formInput, function(data){ ... }); $.post($('#myForm').attr('action'),formInput, function(data){ ... }); My question is how do I use jQuery to get and manipulate the data that the PHP function retrieves from the DB? Thanks in advance for any assistance.
supposed that you are using get to call server side $.get('yourpage.php', function(){}); on yourpage.php print out all the values you needed BUT in json_encode form - put all values into an array, $arr = array('value1'=>'somevalue', etc...); echo json_encode($arr); on the function $.get('yourpage.php', function(){}); just use eval to decode the json encoded array $.get('yourpage.php', function(data){ eval(data); }); it will now set a private array variable IN js form alert(value1);
U can use AjaxRequest.js which are availlable on Internet. Just search on Google and you will find it. Its easy to create dynamic application with that Jquery Class. All the best..
So, so far you are able to retrieve the data through a click and now you want that information to write into a box ? $box_id_name = the textarea box where you want to write $the_results = the data from the click It should write into the boxes, untested though. <div onclick="javascript:document.getElementById('$box_id_name').value='$the_results'"> Code (markup):