I have an HTML search script and I need to change the button text on click from "Search" to "Please Wait..."
enter <form action="form.php" method="post"> Search: <input type="text" name="term" /><br /> <input type="submit" value="Submit" /> </form>
I have an HTML search script and I need to change the button text on click from "Search" to "Please Wait..."
enter <form action="form.php" method="post"> Search: <input type="text" name="term" /><br /> <input type="submit" value="Submit" /> </form>
You can use jquery for this purpose
First, you need to add the id to form and the submit button
enter <form action="form.php" id="form" method="post">
Search: <input type="text" name="term" /><br />
<input type="submit" id="submit" value="Submit" />
</form>
Then in jQuery code
$(document).ready(function(){
$("#form").submit(function(){
$("#submit").val("Please Wait...");
});
});
Plus, don't forget to include jQuery library in the head tag
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.0/jquery.min.js"></script>
For this, you should use Javascript and the simple way is to use Jquery event's
Include the Jquery library
<script src="https://code.jquery.com/jquery-3.4.1.min.js"></script>
Add class to your form or Submit Button to select and access the element easily
<form action="form.php" method="post">
Search:
<input type="text" name="term" /><br />
<input type="submit" class="submit-btn" value="Submit" />
</form>
Then use Jquery click() event
<script>
$(function() {
$(".submit-btn").click(function() {
$(this).val('Please Wait...');
});
});
</script>
The full code:
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>My app</title>
</head>
<body>
<form action="form.php" method="post">
Search:
<input type="text" name="term" /><br />
<input type="submit" class="submit-btn" value="Submit" />
</form>
<script src="https://code.jquery.com/jquery-3.4.1.min.js"></script>
<script>
$(function() {
$(".submit-btn").click(function() {
$(this).val('Please Wait...');
});
});
</script>
</body>
</html>
It works but note that you should use AJAX to be prevent page reload and see the change prefectly