Forums

Ajax Programming

anil_admin 13 Jul, 2015
Hii sir,

i want to write ajax programming for retrieving information using id and displayed into dropdown.
I have write the logic for that,but i dont know how to put that into Chronoforms.
Please help me.
GreyHead 13 Jul, 2015
Hi anil_admin,

Please check the FAQs for double drop-down. I think that is what you are trying to do.

Bob
anil_admin 13 Jul, 2015
Thanx sir reply my queries,

sir but i want to fetch the database using id.
Autofill the dropdowns and radiobutton.

Actually i have done this on localhost,it works properly.
but how it could be use in chronoforms..
GreyHead 13 Jul, 2015
Hi anil_admin,

The host shouldn't make any difference - if it works on localhost then it should work similarly in a form.

The double-drop-down won't work for radio buttons (but you didn't mention those in your first post).

You can do this putting your Ajax JavaScript into a Load JavaScript action and the code to return the look-up values in a new event; then set the Ajax URL to link to that event e.g. ...&event=ajax

Bob
anil_admin 13 Jul, 2015
SIr actully i have to build 2 php file . one for ajax programming and another for fetching data code .
so, how to add these 2 file codes in chronoforms in DBRead(on found) event.In the textbox when i have to type any number it will be fired into the database and get back the database.

ajax.php:Ajax code

<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript">
$(document).ready(function(){
	$("#code").keyup(function(){
		console.log("keyup");
		//ajax starts
		$.ajax({
		  type: "POST", 
		  url: "ajax1.php", 
		  data: { q: $("#code").val()} 
		}).done(function( msg ){ 
					
	      console.log(msg);
		  
          obj = JSON.parse(msg);
		  console.log(obj[0]);
		  console.log(obj);
		  $("#projectname").val(obj[0]); 
	        $("#fund").val(obj[1]); 
               	});	
	});
});
</script>

fetch.php: These is my fetch code

<?php
$q = $_REQUEST['q'];
if($q!="")
{
	$con = mysql_connect("localhost","root","");
	if(!$con)
	{
		die("Error has occured");
	}
	mysql_select_db("normal");

	$query="SELECT * from normal WHERE code=$q";//selecting names of cities
	
	$result = mysql_query($query,$con);
	if(mysql_num_rows($result)>0)
		{			
		while($row=mysql_fetch_assoc($result))
			{
			 $output=array($row['projectname'],$row['fund']);
			 
			}
			echo json_encode($output);
		}
}
?>


Sir how to add these 2 files .
GreyHead 13 Jul, 2015
Hi anil_admin

You can do this putting your Ajax JavaScript into a Load JavaScript action and the code to return the look-up values in a new event; then set the Ajax URL to link to that event e.g. ...&event=ajax

You don't need to load the jquery.js file and you don't need <script> tags in the Load JavaScript box.

Bob
anil_admin 15 Jul, 2015
Hello sir,

I have to fetch value from database using ajax and json and it will be put down into dropdown .
but when i enter another code into "code" textbox the previous value is still in the dropdown and next value come down in dropdown.
var projectname = msg.projectname;
jQuery("#projectname").append($('<option>', {
 text: projectname
  }));

So how i select particular value in the dropdown that i fetch from the database.
GreyHead 15 Jul, 2015
Hi anil_admin,

I'm sorry I really don't understand what you are trying to do here.

If you want to set the new option as selected then you can do that in your jQuery code.

Bob
This topic is locked and no more replies can be posted.