2 dropdown list created by jQuery using ajax
Hi,
I have 1 dropdown list that list all employers (option value is the employer ID).
When user select in this list an employer, i create (in jQuery / AJAX) another dropdown list with contact person working for the selected employer.
when user select a contact person from this second list, i would like to display the contact person email into a simple input textbox.
my problem is that selecting the contact person does not display his email into the input textbox.
using FireBug i saw that my second list (contact persons) do not run the ajax call :(
here is my code:
- function ajaxGetContacts(){
- var targ = jQuery("select[name='jform[employer_id]']");
- var url="index.php?option=com_rgtmyra&view=job&layout=edit&task=job.getcontacts&emp_id="+targ.val();
- var a=new Request.JSON({
- url:url,
- method:'get',
- onSuccess: function(response){
- jQuery('.updated-contact').html(response.html);
- }
- }).send();
- }
-
-
-
- function ajaxGetContactEmail(){
- var targ = jQuery("select[name='jform[contact_id]']");
- alert("contact id "+targ.val());
- var url="index.php?option=com_rgtmyra&view=job&layout=edit&task=job.getcontactemail&c_id="+targ.val();
- var a=new Request.JSON({
- url:url,
- method:'get',
- onSuccess: function(response){
- jQuery("input[name='jform[application_email]']").val(response.html);
- }
- }).send();
- }
- jQuery("#jform_employer_id").change(
- function(){
- alert("change employer ID");
- ajaxGetContacts();
- });
-
- jQuery("#jform_contact_id").change(
- function(){
- alert("change contact ID");
- ajaxGetContactEmail();
- });
- // to initialize the form
- ajaxGetContacts();
-
- ajaxGetContactEmail();
I know that both ajax methods and their return value are ok because i tested them..
i just have the feeling that when the first dropwdown is created, the function:
- jQuery("#jform_contact_id").change(
- function(){
- alert("change contact ID");
- ajaxGetContactEmail();
- });
is not available...
any idea ?
thx.