I want to execute the javascript code through php when the submit button is clicked……this code does it but the page refreshes…..i dont want the page to refresh……can I achieve it through ajax or jquery and how?
<html>
<head>
<style>
.popup
{
visibility:hidden;
}
</style>
</head>
<body>
<form method="post">
<div id="Popup" class="popup">
Sorry! The vehicle is already booked on the corresponding date.
Select a different date or book another vehicle.
</div>
<input type="submit" name="submit" value="display">
</form>
<?php
if(isset($_POST["submit"]))
{
echo '<script>document.getElementById("Popup").style.visibility="visible";</script>';
}
?>
</body>
</html>
2
Answers
try to use javascript to execute on second plane the code
You cannot do this with PHP. As PaulProgrammer stated PHP can only execute when the page is generated as it is a server side language. You need a client side language such as JavaScript to do this. Here is an example of code you can try out. Don’t just take the example, but learn what each of the components do: