DB Read based on dropdown selection

tshirley 05 Nov, 2014
Hello,

I have a form with a dropdown selection and I want to use the selection to look up a database table row and populate another field in the form.

I have created a new event and placed a DBRead in it, and then I was not sure how to set up the Events tab of the dropdown to cause the event to run.

Can you help me please?
Max_admin 05 Nov, 2014
Hi Tim,

Your dropdown must have an empty value (the first one) then in your dropdown events, set an event when value != "" (empty)

Select the "Function" method, and write the function name as "ajax_call".

Now, add a "Load JavaScript" action and use this code:


function ajax_call(){
$.ajax({
	"type" : "GET",
	"url" : "link to form &event=new_event_name",
	"success" : function(res){
		$("field_id").val(res);
	},
});
}


Regards,
Max
Max, ChronoForms developer
ChronoMyAdmin: Database administration within Joomla, no phpMyAdmin needed.
ChronoMails simplifies Joomla email: newsletters, logging, and custom templates.
tshirley 05 Nov, 2014
Thanks,

So to use a real example, I have a table with a name and an email address so I set up an event called "getemail" with a DBRead action to retrieve the data.

I have in my dropdown the values 1=Smith, 2=Jones. And a blank row as you indicate.

function ajax_call(){
$.ajax({
 "type" : "GET",
 "url" : "http://mydomain.com/component/com_chronoforms5/chronoform,MyForm/&event=getemail",
 "success" : function(res){
  $("email").val(res);
 },
});
}

I'm slightly puzzled still, by the last line of code - what is the effect of the line beginning "function(res){......" ?
Max_admin 05 Nov, 2014
The line you mentioned is just a function to call after the AJAX successfully gets the result!

Please use the form link from the form's manager, right click the "view form" and select "copy link"

Regards,
Max
Max, ChronoForms developer
ChronoMyAdmin: Database administration within Joomla, no phpMyAdmin needed.
ChronoMails simplifies Joomla email: newsletters, logging, and custom templates.
This topic is locked and no more replies can be posted.