I make an ajax call to populate a select
This works:
I want to then populate the rest of the form with data that was returned from the ajax call
I tried this but the data object is undefined. How do I pass the data object into the change event
$.ajax({
url: "/_handlers/[login to view URL]",
data: {userRole_ID: 1300},
dataType: 'json',
type: 'POST',
contentType: 'application/x-www-form-urlencoded',
success: function (data) {
$('#ddl_users').html('<option value="0" title="Add a new client user"> Add New</option> ');
$.each(data, function (index, item) {
$('#ddl_users').append('<option value="'
+ [login to view URL]
+ '" title="'
+ [login to view URL]
+ '">'
+ [login to view URL]
+ '</option>');
})
$('#ddl_users').on('change',function (data) {
//alert('hi');
alert($(this).val());
$.each(data, function (index, item) {
alert([login to view URL]);
//if ($(this).val() == [login to view URL]) {
// alert('match:' + $(this).val() + ': ' + [login to view URL]);
//}
});
});
},
error: function (data, status, jqXHR) {
alert('There was an error loading User Data.');
}
});
Hi,
The on change handler will contain the dropdown object as first parameter. It won't contain the data object.
My suggestion would be while creating option, create an data attribute which contains the whole user object returned in ajax call. Then the user object can be accessed in on change handler for selected option $(this).find(option:selected).attr(data-user) and the rest of the form can be filled based on it.
If you understand it implement on you own, no need to accept the bid. If you want, i can do it for you.
Regards,
Kasi
$10 USD in 1 day
4.9 (12 reviews)
4.2
4.2
6 freelancers are bidding on average $13 USD for this job
hello sir,
i can do your project.... please accept my bid so that i can start it... i m expert in this type of project... u can also see my portfolio... please sir accept my bid.. please
hope u will do
i m waiting for your response..
thank you.. :)
Hello Sir/Mam,
I have 5 years of experience in the field of web development and designing.
I can assure you that your work will be done in given time and in full professional way.
Awaiting your positive response.
Thanks & Regards
HarbourSpace
Hello Friend
I have read your project very carefully and I understand what you want.
thanks for good and clear explanation I have almost done many work like this.
I have very good hold on HTML, PHP, MYSQL, Jquery, etc.
I am very confident about this job and I can manage stuff very well and make you smile.
Thanks