普通网友 2016-10-30 21:09
浏览 43
已采纳

PHP和JAVASCRIPT - 如何在单击连接到每个输入字段的按钮后从多个输入字段中获取值? [关闭]

I want to create a subpage for changing the username, password, mail etc. I have 4 inputs and 4 buttons next to each input in my php file. I am wondering, how can I take the value from one of the input field after clicking on the button next to it? I want to take that values without reloading the page. What's more first click on the button changes the input field from "disabled" (in PHP) to "prop('disabled', false)" (in JAVASCRIPT). Then, you can enter something into the input field. The second click on the same button changes similarly (from "abled" to "disabled"). So I want to take the input value after SECOND CLICK on the button.

HELP ME! :<

My code: [HTML] https://i.stack.imgur.com/JE9K9.png [JAVASCRIPT] https://i.stack.imgur.com/syoKa.png

  • 写回答

1条回答 默认 最新

  • dpjjmo3079 2016-10-30 21:13
    关注

    You could do something through jQuery:

    $('.edit_profile').on('click', function(){
       // if still disabled, return;
       if ($(this).prev().is(':disabled')) return;
       // otherwise we go for value:
       var value = $(this).prev().val();
       console.log(value);
    });
    

    And please take a look for function: prev() https://api.jquery.com/prev/

    For passing your fields to php use ajax:

    $.ajax({
        type: "POST",
        url: "myphpscriptforupdate.php",
        dataType: 'html',
        data: { 
            p_year: $('#p_year').val() 
        },
        success: function(data){
            // data = response from php (the things you echoed)
            }
    });
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 运筹学排序问题中的在线排序
  • ¥15 关于docker部署flink集成hadoop的yarn,请教个问题 flink启动yarn-session.sh连不上hadoop,这个整了好几天一直不行,求帮忙看一下怎么解决
  • ¥30 求一段fortran代码用IVF编译运行的结果
  • ¥15 深度学习根据CNN网络模型,搭建BP模型并训练MNIST数据集
  • ¥15 C++ 头文件/宏冲突问题解决
  • ¥15 用comsol模拟大气湍流通过底部加热(温度不同)的腔体
  • ¥50 安卓adb backup备份子用户应用数据失败
  • ¥20 有人能用聚类分析帮我分析一下文本内容嘛
  • ¥30 python代码,帮调试,帮帮忙吧
  • ¥15 #MATLAB仿真#车辆换道路径规划