doushui3216 2018-04-19 06:43
浏览 52

如何使用多个选择选项值更新数据库:Wordpress

I am having a custom table that has several items and has a column of status. I have created a dropdown using select for changing the status.

Here, what I want to do is, on change of the status select option, the value of status of that particular row should be updated in the db. I am able to get the value of the select using jquery but I am not sure how to update the table when multiple dropdowns are being selected together.

I am having the below select options,

  <select id ="update-statusDropDown">
  <option name="waiting" value="waiting">Waiting</option>
  <option name="due" value="due">Due Diligence</option>
  <option name="escrow" value="escrow">Escrow</option>
  <option name="inspection" value="inspection">Inspection</option>
  <option name="closed" value="closed">Closed</option>
</select>

My jQuery is something like below,

jQuery(document).ready(function () {

    jQuery('select#update-statusDropDown').change(function () {

        //Selected value
        var inputValue = $(this).val();
        alert("value in js " + inputValue);

        //Ajax for calling php function
        jQuery.post('update-listing-status.php', {dropdownValue: inputValue}, function (data) {
            alert('ajax completed. Response:  ' + data);
            //do after submission operation in DOM
        });
    });
});

I want to update status value in the table as per the 'inputValue' from the dropdown. Also, if multiple dropdowns are selected together, how can I update all the values together. Please can anyone help?

The screenshot of my current table is attached.enter image description here

  • 写回答

1条回答 默认 最新

  • douyi3767 2018-04-19 07:37
    关注

    You have registered the change event of the select using the ID of that drop down which means only the drop down with that ID will trigger the request you making via the jquery.post

    instead use class attribute for the select elements and register the change event on that class

    now to get the unique element you can use the data attribute of that select element and option for example data-tableid="something"

    in this case you can register all change event of all select elements and be able to extract the values that is only unique to the given table or column name.

    $('.class-name').on( 'change' , function(){
    
      // Get the Select itself
      var me = $(this);
      var tableid = me.data('tableid');
      var something = $(this).find(':selected').data('something');
    
      console.log( tableid );
      console.log( something );
    
    } );
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
    <select class="class-name" data-tableid="table-id">
      <option value="the value" data-something="some value 2">The Title 2 </option>
        <option value="the value" data-something="some value">The Title</option>
    </select>

    So now since you have the ability to uniquely identify which select is being used and which option is being used you can make the request as you wish.

    </div>
    
    评论

报告相同问题?

悬赏问题

  • ¥15 微信公众平台自制会员卡可以通过收款码收款码收款进行自动积分吗
  • ¥15 随身WiFi网络灯亮但是没有网络,如何解决?
  • ¥15 gdf格式的脑电数据如何处理matlab
  • ¥20 重新写的代码替换了之后运行hbuliderx就这样了
  • ¥100 监控抖音用户作品更新可以微信公众号提醒
  • ¥15 UE5 如何可以不渲染HDRIBackdrop背景
  • ¥70 2048小游戏毕设项目
  • ¥20 mysql架构,按照姓名分表
  • ¥15 MATLAB实现区间[a,b]上的Gauss-Legendre积分
  • ¥15 delphi webbrowser组件网页下拉菜单自动选择问题