@codewitchJul 20.2021 — #Hello. If I understand your problem correctly, you need php session variables. Those are variables whose values are shared among multiple pages. After user submits the form for the first time, you change value of a session variable and then use this code: <i> </i><form action="script.php" onsubmit="return false"> <input type="text" name="stream" style="width:200px;"> <input type="submit" value="send"> </form>
Which disables use of the button again.
To answer your question, yes, you can use Javascript to disable the button, but I don't see a way how to use Javascript to disable the second attempt, that is why I suggested the use of the php session variables.
@codewitchJul 20.2021 — #Here is your first file: <i> </i><!-- here is file index.php -->> <!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"/> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>hey I am a title</title> <style>
<i> </i></style> </head> <body>
<?php // set a session variable $_SESSION["numberOfClicks"] = "zero";
and here is your second file: <i> </i><!-- here is file script.php -->> <!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"/> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>hey I am a title</title> <style>
@codewitchJul 20.2021 — #Here is your first file: <i> </i><!-- here is file index.php -->> <!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"/> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>hey I am a title</title> <style>
<i> </i></style> </head> <body>
<?php // set a session variable if($_SESSION["numberOfClicks"]!="one"){$_SESSION["numberOfClicks"] = "zero";}
and here is your second file: <i> </i><!-- here is file script.php -->> <!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"/> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>hey I am a title</title> <style>
@codewitchJul 20.2021 — #<i> </i><!DOCTYPE html> <html> <head> <title>Disable button using disabled property</title> </head> <body> <p>Click the button to submit data!</p> <p> <form action="script.php" method="POST"> <input type="text" name="stream" style="width:200px;"> <input type='submit' value='Submit' id='btClickMe' onclick='save(); this.disabled = true;' /> </form> </p> <p id="msg"></p> <script> function save() { var msg = document.getElementById('msg'); msg.innerHTML = 'Data submitted and the button disabled.'; } </script> </body> </html>
Now there is a form.
If you press tabulator key on your keyboard to "activate" the button, it gets submitted after by pressing enter key.
But if a user reloads the page they can submit it again, that is why I think the php session variables are a better solution, depending on what you need.
EDIT: moderators please delete post number 4 in this thread, there is a corrected code in post number 6, thank you