I have the following form and after the "Join" button is clicked, it should change to a delete button. I want to change the text to say delete and change what it does.
This is my code:
<form action="riderJoin.php" method="post">
<input type ="hidden" name = id value="<?php echo $row['post_id']; ?>" >
<input type =submit class="edit_btn " name = "submit" value = "Join">
</form>
<script type="text/javascript">
var x = document.getElementsByClassName('edit_btn');
<?php if (isset($_POST['submit'])) { ?>
var i = <?php echo $_SESSION['postId'] ; ?> - 1 ;
var y = x[i];
x[i].textContent = "Delete";
x[i].style.backgroundColor = "red";
x[i].style.color = "white";
<?php }?>
</script>
I have get the button by class name into var x
and grab an item inside the x using x[i]
, but when I try to change the text content it doesn't change. However, when I set the background colour to red, it works perfectly.
What have I done wrong?