[英]add elements in 2nd dropdown list depending upon the element selected in 1st dropdown using jquery and php
I'm trying to populate Cities as per the State selected by user in dropdown lists.我正在尝试根据用户在下拉列表中选择的州来填充城市。
I've a function in jquery defined as:我在 jquery 中定义了一个函数:
function onchange1(dropdownmenu,field_name,id)
{
alert(field_name);
$.post(
'wppb.city.php',
{ field_name: id},
function(data) {
alert(data);
$('#'+dropdownname).html(data);
alert("Data Loaded: " + data);
});
alert($('#'+dropdownname).html());
}
and I'm trying to get values from the location where I've called this function.我正在尝试从我调用此函数的位置获取值。 I've called this function in html tags as:
我在 html 标签中调用了这个函数:
<select name="state" id=state onChange="onchange1(city,state,this.value);">
where city is the name of my 2nd dropdownmenu, state is the field_name and this.value is the id.其中 city 是我的第二个下拉菜单的名称,state 是 field_name,this.value 是 id。
But when this function is being called and when alerted it's showing [objectHTMLSelectElement].但是当这个函数被调用并且收到警报时,它会显示 [objectHTMLSelectElement]。
How to retrieve values from HTML and use it in jquery function ?如何从 HTML 检索值并在 jquery 函数中使用它?
I believe what you want is我相信你想要的是
$('#'+field_name.id).val()
You might also want to look into serializeObject , a good post is this Convert form data to JavaScript object with jQuery您可能还想查看 serializeObject ,一个很好的帖子是使用 jQuery 将表单数据转换为 JavaScript 对象
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.