Click here to Skip to main content
15,904,297 members
Please Sign up or sign in to vote.
2.00/5 (1 vote)
See more:
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....

JavaScript
<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;
}

//alert("Thank you for your Enquiry. Our representative will contact you shortly. Please press Ok.");
	

}
</script>

HTML
<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
 <?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';
}
?>
Posted
Updated 27-Jun-12 23:51pm
v2

I can see two things wrong with
<form action="" name="WebToLeadForm" method="post" id="WebToLeadForm" onsubmit="javascript: return form_validation();" >

1. You need to specify a URL as the argument to action=

2. The last bit should be
onsubmit="return form_validation()"
(You don't want javascript:)

Peter

[edit] fixed typo - missing quote [/edit]
 
Share this answer
 
v2
Comments
[no name] 28-Jun-12 5:23am    
not working sir..
Put you captcha tags inside update panel.
Page won't refresh..

XML
<img id="imgid" src="CaptchaSecurityImages.php?width=100&height=40&characters=5" />
Can't read the image?   click hereto refresh
Security Code:*     <input id="security_code" name="security_code" type="text" style="width:100px;"/>



Thanks,

Ashish

Mark it solution so that other may refer to the answer.
 
Share this answer
 
Comments
[no name] 28-Jun-12 5:23am    
but how thats what i am asking?
can u give me code..
XML
<asp:ScriptManager ID="ScriptManager1" runat="server">
        </asp:ScriptManager>


C#
<asp:updatepanel id="UpdatePanel1" runat="server" xmlns:asp="#unknown">
<contenttemplate>
          <img id="imgid" src="CaptchaSecurityImages.php?width=100&height=40&characters=5" />
          Cant read the image?   click hereto refresh
          Security Code:*     <input id="security_code" name="security_code" type="text" style="width:100px;"/>
</contenttemplate>
</asp:updatepanel>



You have to add reference of ajax library for using UpdatePanel.

please follow the link for better understanding of UpdatePanel

http://msdn.microsoft.com/en-us/library/bb399001.aspx[^]

See example

http://www.scratchmysoul.com/register.aspx[^]


Thanks,

Ashish

Mark it as a answer so that other may refer to the answer.
 
Share this answer
 
v3
Comments
[no name] 28-Jun-12 5:44am    
Thanks buddy but i am using php. so it may be either in java script or in php/html...
PHP
<?php
session_start();
if($_SESSION['referer'] == "http://{$_SERVER['HTTP_HOST']}{$_SERVER['REQUEST_URI']}")
{
    die("please do not go back");

}

$_SESSION['referer'] = $_SERVER['HTTP_REFERER'];
?>
 
Share this answer
 
Hi,
Finally i put code so that if the page will refresh then the data will not lost.
HTML
  <option value="Mr."<?php echo ($salutation =="Mr."?"selected='selected'":""); ??>>Mr.</option>
<input id="first_name" name="first_name" type="text" style="width:150px;"  value="<?php echo htmlentities($fname) ??>" />
<textarea id="description" name="description" type="text" style="width:150px;"><?php echo htmlentities($detail) ??></textarea>

<tr>
                <td>Demo Required: </td>
                <td><input name="demo" type="radio" value="yes"<?PHP echo $yes; ??> />
                  Yes 
                    
                  <input name="demo" type="radio" value="no"<?PHP echo $no; ??>  />
                  No</td>
              </tr>

<input id="printerhp_c" name="printerhp_c" type="checkbox" value="HP"<?php echo empty($_POST['printerhp_c']) ? '' : ' checked="checked" '; ??> />


Thanks
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900