I have written php code to retrieve data from database to div in webpage.i have another form that has a submit button,when i click on that button that will do a function of retrieving the database values and that values will be displayed in a division. i have the following code in the division how to clear it using button.
this is php code that retrieves when the value is submitted from previous form
<div id="result" style="margin-left:10px;">
<?php
mysql_connect("localhost", "root") or die (mysql_error ());
mysql_select_db("theaterdb") or die(mysql_error());
$strSQL =("SELECT theater_name,address FROM theaters WHERE theater_name='" . mysql_real_escape_string($_POST['course']) . "'");
$rs = mysql_query($strSQL);
while($row = mysql_fetch_array($rs)) {
echo "<b>Theater Name:</b><br>";
echo $row['theater_name'] . "<br /><br /><br />";
echo "<b>Theater Address:</b><br>";
echo $row['address'] . "<br />";
}
mysql_close();
?>
i have the following HTML code for a button
<form method="post">
<input type="reset" value="reset" />
</form>
i am using this button.when i click this button it should clear the contents of division, how to do this..can anyone help me....
Thanks in advance....
Reset button couldn't clear the DIV
content. You can do it using your form Submit Event. In plain javascript it should be something like this:
<script>
function clear_div() {
document.getElementById("result").innerHTML = "";
}
</script>
<div id="result"></div>
<form method="POST" action="process.php" onsubmit="clear_div()">
<input type="submit">
Using jQuery:
$("form").submit(function(e){
e.preventDefault();
$("#result").empty();
});
You can do it with jQuery if you have it
$('input[type="reset"]').on('click', function(e){
e.preventDefault();
$('#result').empty();
})
Example: jsFiddle