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

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)
        }
});