Populate value of a dropdown based on another dropdown value change

Discussions related to customizing hooks. Hooks are documented at http://bigprof.com/appgini/help/advanced-topics/hooks/
Post Reply
lawrencekeru
Posts: 28
Joined: 2016-06-24 02:51

Populate value of a dropdown based on another dropdown value change

Post by lawrencekeru » 2019-08-27 17:29

Hi Gurus,

When Invoice No below is selected, I want to populate value of Tenant.

Am using the below code

Code: Select all

$j(document).on('change','#invoice_no-container', function(){
	var invoiceid = $j('#invoice_no').val();
	// console.log(invoiceid);
	if ( invoiceid == '{empty_value}' ) {
		$j('#tenant').val('');
	}else{
		$j.ajax({
			url: 'ajax_payment.php',
			data: { invoiceid:invoiceid },
			success: function(resp){
				var response = JSON.parse(resp)
				console.log(response.tenantid);
				$j('#tenant').val(response.tenantid).trigger('change');
			}
		});
	}
});
The Tenant dropdown is not populating the name.

When I inspect the element, the value is set as below

Code: Select all

<input type="hidden" name="tenant" id="tenant" value="27">
Please assist.
Attachments
capture(251).png
capture(251).png (7.48 KiB) Viewed 114 times

pböttcher
AppGini Super Hero
AppGini Super Hero
Posts: 553
Joined: 2018-04-01 10:12

Re: Populate value of a dropdown based on another dropdown value change

Post by pböttcher » 2019-08-28 09:08

Hi,

is the tenant a single selection field, or is it bound in appgini to the Invoice No?

If it is a single field (which I assume now). Is the value you want to display in the dropdown the same that you want to have in the field? Like the 27 in your example?

If that is the case you can try

Code: Select all

		$j.ajax({
			url: 'ajax_payment.php',
			data: { invoiceid:invoiceid },
			success: function(resp){
				var response = JSON.parse(resp)
				console.log(response.tenantid);
				$j('#tenant').val(response.tenantid).trigger('change');
				$j('#tenant').text(response.tenantid); 
				$j('#s2id_tenant-container').find('.select2-chosen').text(response.tenantid);
				AppGini.current_tenant.value=response.tenantid;			}
		});

lawrencekeru
Posts: 28
Joined: 2016-06-24 02:51

Re: Populate value of a dropdown based on another dropdown value change

Post by lawrencekeru » 2019-08-28 13:06

Hi pbottcher,

Its works well, thanks sir!

Post Reply