function postal_set_address(button) { var url = "http://www.gg-gardens.com/wp-content/plugins/cforms/postal/find.php"; var a = jQuery(button); var pcode=find_parents_child(a,'.postalfield'); var pref=find_parents_child(a,'.preffield'); var addr=find_parents_child(a,'.addressfield'); var proc=function(json){ if(! json.error) { pref.val(json.pref); addr.val(json.addr); }else{ alert(json.error); } }; var param={ pcode : pcode.val() }; jQuery.getJSON(url,param , proc); } function find_parents_child(me,expr) { var c; var p=me; do { p=p.parent(); c=p.find(expr); }while(c.length==0 && p.length>0); return c; }