Code :
jQuery(document).ready(function(){ refresh(document.getElementById('elementPere1').value, 'elementFils1', elementFilsSelected', 'nameServlet'); }); function refresh(dadId, sonName, selectedName, servletName){ jQuery.ajax({ type: "GET", url: "/chemin/" + servletName + ".view", data: "dadId=" + dadId, dataType: "xml", success: function(result){ var selectedValue = document.getElementById(selectedName+'').value jQuery('#' + sonName).empty() jQuery(result).find('item').each(function(){ var id_text = jQuery(this).find('value').text(); var name_text = jQuery(this).find('name').text(); if (selectedValue == id_text){ jQuery('<option selected=\"selected\" value=\'' + id_text + '\'>' + name_text +'</option>').appendTo('#' + sonName); }else{ jQuery('<option value=\'' + id_text + '\'>' + name_text +'</option>').appendTo('#' + sonName); } }); } }); }
|