0

I'm trying to create a page where a user can manage the profile details, Below is my HTML code with a little tricky JS function to make it user-friendly.

<script>
function changeText(button,input)
{
var x = document.getElementById(button);
  if (x.innerHTML == "Edit") {
    x.innerHTML = "Save";
    x.value="Save";
    document.getElementById(input).readOnly=false;
    document.getElementById(input).focus();
    document.getElementById(input).select();
  }
  else if (x.innerHTML == "Save")  {
    x.value="Edit";
    x.innerHTML = "Edit";
    document.getElementById(input).readOnly=true;
  }
}
</script>

<form method="post">
    <input type="text" id="i1" value=<?php echo $currentFirstName;  ?> onkeyup="checkName(this.value)" name="newfname" placeholder="First Name" readonly>
    <button type='button' name="b1" id="b1" value="Edit" onclick="changeText('b1','i1')">Edit</button>
</form>

And, my PHP code has something like that.

if(isset($_POST['b1']) && $_POST['b1']=="Save"){
//update user data in DB
}

I have used PHP var_dump() function to check what is the value of isset($_POST['b1']) and the value of $b1 itself. it is returning false and NULL. So, what is the problem here? because I went over my code many times and I don't see something unusual.

Ahmed Kena
  • 27
  • 6

1 Answers1

-1

<script>
    
    function changeText(button,input) {
        var x = document.getElementById(button);
        if (x.value == "Edit") {
            x.innerHTML = "Save";
            x.value="Save";
            document.getElementById(input).readOnly=false;
            document.getElementById(input).focus();
            document.getElementById(input).select();
        } else {
            x.value="Edit";
            x.innerHTML = "Edit";
            document.getElementById(input).readOnly=true;
        }
    }
</script>

<form method="post">
    <input type="text" id="i1" value="Test Name" onkeyup="checkName(this.value)" name="newfname" placeholder="First Name" readonly>
    <button type="button" name="b1" id="b1" value="Edit" onclick="changeText('b1','i1')">Edit</button>
</form>
Gabor
  • 566
  • 5
  • 14