I have a contact form on div, I just want to hide the div after mail sent .. My below code is not hiding the contact form
<?php
if(mail($to,$subject,$body,$headers))
{
echo "<script type='text/javascript'>";
echo "hideDiv();"
echo "</script>";
$msg="We have received your enquiry. We will contact you soon.";
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<script type="text/javascript">
function hideDiv()
{
document.getElementById("contact_form_div").style.display="none";
}
</script>
</head>
<body>
<form onsubmit="return validate()">
<!-- contact form content-->
<input type="submit" value="submit" name="submit" />
</form>
</body>
</html>
There is no div in your code... You need to identify the form you want to hide => add an ID
<form onsubmit="return validate()" id="myID">
Or add a div which wrap the form
<div id="myID">
<form onsubmit="return validate()">
<!-- contact form content-->
<input type="submit" value="submit" name="submit" />
</form>
</div>
Then hide the form or div by selecting the ID :
document.getElementById("myID").style.display="none";
What happens if someone has javascript turned off? Why not decide what to show with if - else in php?
<?php
if(mail($to,$subject,$body,$headers))
{
echo "We have received your enquiry. We will contact you soon.";
}
else
{
?>
<form onsubmit="return validate()">
<!-- contact form content-->
<input type="submit" value="submit" name="submit" />
</form>
<?php
}
?>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.