Hi,
Hello every one, i need a help to prevent page refresh or reload.
I have a page as contact details.
and i have put java script on every textbox.
but after submitting the security code it refresh the page and all textboxes data lost, even if the code is wrong.
i only want that if the code is wrong it remain in the same page and data of textboxes remain as it was filled only security code textbox show blank.
I have sent you all the code it is in the same page..
pls go through it and help me to solve it..
its very urgent...
thanks in advance....
<script type="text/javascript">
function form_validation()
{
hh=document.WebToLeadForm;
if(hh.first_name.value==""){
alert("Please enter your first name.");
hh.first_name.focus();
return false;
}
if(hh.last_name.value==""){
alert("Please enter your last name.");
hh.last_name.focus();
return false;
}
if(hh.account_name.value==""){
alert("Please enter company name.");
hh.account_name.focus();
return false;
}
if(hh.webtolead_email1.value==""){
alert("Please enter your email address");
hh.webtolead_email1.focus();
return false;
}
if (hh.webtolead_email1.value.indexOf('@') == -1){
alert("Invalid email address");
hh.webtolead_email1.focus();
return false;
}
if (hh.webtolead_email1.value.indexOf('.') == -1){
alert("Invalid email address");
hh.webtolead_email1.focus();
return false;
}
if(document.getElementById("phone").value.length < 10)
{
alert('Enter your mobile number');
document.getElementById("phone").focus();
return false;
}
if (isNaN(parseInt(document.getElementById("phone").value)))
{
alert('Only Numbers are Allowed');
document.getElementById("phone").focus();
return false;
}
if(hh.product.value==""){
alert("Please select Product Interest.");
hh.product.focus();
return false;
}
if(hh.description.value==""){
alert("Please enter description");
hh.description.focus();
return false;
}
}
</script>
<table width="220" border="0" align="center" cellpadding="0" cellspacing="0" style="font-family:Verdana, Arial, Helvetica, sans-serif; font-size:11px; color:#4c4c4c;">
<form action="<?php echo $_SERVER['PHP_SELF'];??>" name="WebToLeadForm" method="post" id="WebToLeadForm" onsubmit="javascript: return form_validation();" >
<tr>
<td height="30">First Name: <span class="required" style="color:#93B928;">*</span></td>
<td><input id="first_name" name="first_name" type="text" style="width:100px;" /></td>
</tr>
<tr>
<td height="30"><span sugar="slot">Last Name: </span> <span class="required" style="color:#93B928;">*</span></td>
<td><span sugar="slot">
<input id="last_name" name="last_name" type="text" style="width:100px;"/>
</span> </td>
</tr>
<tr>
<td height="30">Company Name: <span class="required" style="color:#93B928;">*</span></td>
<td><span sugar="slot">
<input id="account_name" name="account_name" type="text" style="width:100px;"/>
</span> </td>
</tr>
<tr>
<td height="30">Email: <span class="required" style="color:#93B928;">*</span></td>
<td><span sugar="slot">
<input id="webtolead_email1" name="webtolead_email1" onchange="validateEmailAdd();" type="text" style="width:100px;" />
</span></td>
</tr>
<tr>
<td height="30" valign="top">Contact Number:<span class="required" style="color:#93B928;">*</span></td>
<td valign="top"><input id="phone" name="phone" type="text" style="width:100px;" />
</td>
</tr>
<tr>
<td height="30" valign="top">Product Interest:<span class="required" style="color:#93B928;">*</span></td>
<td valign="top"><select name="product" id="product" style="width:100px;">
<option selected="selected" value="">------None------</option>
<option value="System 444"> System 444</option>
<option value=" System Lite">System Lite</option>
<option value="System Duo">System Duo</option>
<option value="System Plus">System Plus</option>
</select>
</td>
</tr>
<tr>
<td height="30" valign="top">Detail:<span class="required" style="color:#93B928;">*</span></td>
<td valign="top"><textarea name="description" id="description" cols="25" rows="5" style="width:100px;"></textarea></td>
</tr>
<tr>
<td height="30" valign="top"> </td>
<td valign="top"><img id="imgid" src="CaptchaSecurityImages.php?width=100&height=40&characters=5" /></td>
</tr>
<tr>
<td height="30" valign="top"><small>Can't read the image?</small> </td>
<td valign="top">click <a href="java<!-- no -->script: refreshCaptcha();"><small>here</small></a><small>to refresh</small></td>
</tr>
<tr>
<td height="30" valign="top">Security Code:<span class="required" style="color:#93B928;">*</span></td>
<td valign="top"><input id="security_code" name="security_code" type="text" style="width:100px;"/></td>
</tr>
<tr>
<td height="50" valign="top"> </td>
<td valign="top"><input class="button" name="Submit" value="Send" type="submit" /></td>
</tr>
<tr>
<td height="30" valign="top">Security Code:<span class="required" style="color:#93B928;">*</span></td>
<td valign="top"><input id="code" name="code" type="text" value="<?php if(!empty($_SESSION["msg"])) echo($_SESSION["msg"]); ??>" style="width:100px;"/></td>
</tr>
</form>
</table>
<?php <br mode="hold" /?>//session_start();
if(isset($_POST['Submit'])) {
if( $_SESSION['security_code'] == $_POST['security_code'] && !empty($_SESSION['security_code'] ) ) {
// Insert you code for processing the form here, e.g emailing the submission, entering it into a database.
//echo 'Thank you. Your message said "'.$_POST['message'].'"';
//echo 'Thank you. Your message said "';
$_SESSION['first_name'] = $_POST['first_name'];
$_SESSION['last_name'] = $_POST['last_name'];
$_SESSION['account_name'] = $_POST['account_name'];
$_SESSION['webtolead_email1'] = $_POST['webtolead_email1'];
$_SESSION['phone'] = $_POST['phone'];
$_SESSION['product'] = $_POST['product'];
$_SESSION['description'] = $_POST['description'];
echo "<script>alert('Thank you...')</script>";
header( 'Location:http://localhost/MySQL/test.php' ) ;
unset($_SESSION['security_code']);
}
else {
//Insert your code for showing an error message here
echo "<script>alert('Please check the code...')</script>";
//echo 'Sorry, you have provided an invalid security code';
//header( 'Location:http://localhost/MySQL/captcha.php' ) ;
}
}
else {
//echo 'Sorry, you have provided andasfasdfadfasdfasdde';
}
?>