简体   繁体   English

根据使用 jquery 和 php 在第一个下拉列表中选择的元素,在第二个下拉列表中添加元素

[英]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.

相关问题 根据PHP中选择的第一个下拉列表填充第二个下拉列表 - Populate 2nd dropdown based on 1st dropdown selected in PHP 基于第一个下拉列表的动态第二个下拉列表 - Dynamic 2nd Dropdown-list based on the 1st Dropdown 根据第一个下拉菜单选择填充第二个下拉菜单 - Populate 2nd Dropdown based on 1st Dropdown Choice 如何根据从第一个下拉菜单自动更改的第二个下拉菜单更改第二个文本框的值? - How to change the 2nd textbox value based on the 2nd dropdown that is automatically changed from 1st dropdown? 如何改变 <option>第3个<select>基于第二次变化<select> ,其中第二个是通过使用jquery ajax更改第一个下拉列表的值来绘制的 - How to change <option> of a 3rd <select> based on change in 2nd <select>, where 2nd is drawn by changing value of 1st dropdown using jquery ajax 表单通过jQuery提交第一,通过PHP提交第二 - Form submits 1st via jQuery, 2nd via PHP 如何关联2个下拉列表并在相对于1st的第二个下拉列表中加载数据 - how to relate 2 dropdown and load data in 2nd dropdown in relation to 1st 如何在第1列和第2列的交叉点上填充第3列结果,这些列都来自用户在下拉列表中选择的同一个表? - How can I populate a 3rd column result on intersections of 1st and 2nd columns all from the same table that are selected by the user on dropdown? 仅在选择了第一个选择列表后如何调用/激活第二个选择列表? - How to call/activate the 2nd select list only after 1st select list was selected? 如何在选项标签 select 下拉列表 1st 2nd 3rd 4th 5th 中添加上标。 1ST 我想要 S 大写字母,但我试过 s 将转换为小写 - How to add superscript in option tag select dropdown 1st 2nd 3rd 4th 5th. 1ST I want S captial letters but i tried s will converted to small case
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM