当选择框上的选择发生更改时,请更改具有特定类的所有表单域的值

时间:2016-01-19 04:35:26

标签: javascript jquery

当用户在标识为=IF(AND(C53=D53, C53="STI"), "No OR, Straight to IM", IF(COUNTBLANK(C53:D53)=2, "No Date Input", IF(AND(C53 = "Still Pending", D53>=DATE(2013, 1, 1)), "Error, Check Again", IF(AND(C53>=DATE(2013, 1, 1), D53 = "Still Pending"), TODAY()-C53, IF(COUNT(C53:D53)=2, D53-C53, "not covered"))))) 的选择框中进行选择时:

  • 我想获取所选的值
  • 我想抓取页面上包含some_select_box类的所有表单字段,并更改其所有值以匹配所选值。

我在代码中遗漏了一些明显的东西:

hidden_search_box

回答jsfiddle

3 个答案:

答案 0 :(得分:2)

你的js小提琴中的问题是,你还没有添加jQuery库,所以你应该在你的控制台中遇到Uncaught ReferenceError: $ is not defined这样的错误。

要将jQuery添加到小提琴中,请在javascript面板中单击右上角的图标,然后在库下拉列表中选择jQuery。

答案 1 :(得分:1)

您的代码中有一个拼写错误,在$(".hidden_search_box")中,缺少双引号。

$(function() {
  $(document).on('change', '#some_select_box', function() {
    var selected_value = this.value;
    $(".hidden_search_box").each(function() {
      debugger;
      this.value = selected_value;
    });
  });
})

JSFiddle

答案 2 :(得分:1)

试试这个

$(document).on('change', '#some_select_box', function () {
    $(".hidden_search_box").val(this.val());
    $(".hidden_search_box option[value='"+this.val()+"']").attr('selected','selected');

});