-1

I am trying to write a code of following different user, with inserting values from MySQL table

<td align="center">
<input type="button" name="<?php echo $id; ?>" id="<?php echo $id; ?>" value="suivre"> 
</td>

I want to know if there's any solution after clicking each time on the button and the value change to following

issou
  • 15
  • 4
  • 1
    Does this answer your question? [Changing button text onclick](https://stackoverflow.com/questions/10671174/changing-button-text-onclick) – El_Vanja Mar 15 '21 at 16:51
  • but my id change, how put $id into document.getElementById() – issou Mar 15 '21 at 16:56
  • You don't have to use `getElementById`. See [this comment](https://stackoverflow.com/questions/10671174/changing-button-text-onclick#comment13844521_10671201) for example. – El_Vanja Mar 15 '21 at 17:00
  • it's not working, could you write me a code so I can test it – issou Mar 15 '21 at 17:08

1 Answers1

0

You are unsuccessful because id attribute cannot start with a digit. Try the following basic examples based on the javascript examples you received here

Example1 with getElementById

<input onclick="change()" type="button" name="<?php echo $id; ?>" id="el_<?php echo $id; ?>" value="suivre"> 
<script>
function change(){
  document.getElementById("el_<?php echo $id; ?>").value="Hello world1";
}
</script>

Example2 without id or getElementById

<input onclick="change(this)" type="button" name="<?php echo $id; ?>" value="suivre"> 
<script>
function change(el){
  el.value="Hello world2";
}
</script>
While1
  • 651
  • 4
  • 5