Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 273
  • Last Modified:

If error shows delete textbox data...

hey... below is my current code, but if the user enters the wrong text the error shows but they can still submit the data.... is there away i can stop this by clearing the text or something??

here is a link www.runningprofiles.com/members/upate.php
<?php 
ob_start("ob_gzhandler");
session_start();
error_reporting(E_ALL); 
require_once '../settings.php';?>
<link rel="stylesheet" type="text/css" href="http://www.runningprofiles.com/css/login.css">
<SCRIPT LANGUAGE="JavaScript" SRC="http://www.runningprofiles.com/members/include/formsubmit.js">
</SCRIPT>
<?php include "../info.php"; // sets username/id ect
include "../getuser.php"; // records user view on page
$result = mysql_query("SELECT * FROM pb") or die(mysql_error()); 
//now display all data
 ?>  <fieldset>
                <legend>My pbs</legend>
<div align="center"><br />
     <?php
$result = mysql_query("SELECT * FROM pb Order by uid,distance") or die(mysql_error());
 
echo "<table class=\"profilepbs\" width=195 align=\"center\" cellpadding=\"0\" cellspacing=\"0\">
   <tr><td width=105 bgcolor=\"#FFFFFF\"><div align=\"center\">Distance</div></td><td width=125 bgcolor=\"#FFFFFF\"><div align=\"center\">Pb</div></td></tr>
   <tr>
     <td height=\"1\" colspan=\"2\" bgcolor=\"#000000\"></td>
     <td height=\"1\" colspan=\"2\" bgcolor=\"#000000\"></td>
   </tr>
   ";
while ( $row = mysql_fetch_array($result) ) {echo "<tr><td><center>" . $row["distance"] . "</center></td><td><center>" . $row["pb"] . "</center></td></tr>";
  }
echo "</table>
 <p>";
 ?>
 
 </p>
</div>
<form id="submit">
  <div align="center">
    <p><br>
      Add a new personal best (Enter pb as 2:01.1 or 13:25.3 ect): oh any your id is <?php echo $id;?>    </p>
    <table>
      <tr>
  <td></td><td> <select name="distance" onchange="setDistance(this.value)">
					<option value="#|Distance">Select the distance</option>
					<option value='withoutMinutes|100m' >100m</option>
                    <option value='withoutMinutes|200m'>200m</option>
                    <option value='withoutMinutes|400m'>400m</option>
                    <option value='withoutHours|800m'>800m</option>
                    <option value='withoutHours|1500m'>1500m</option>
                    <option value='withoutHours|3000m'>3000m</option>
                    <option value='withoutHours|5000m'>5000m</option>
                    <option value='withoutHours|10,000m'>10,000m</option>
                    <option value='withoutHours|5k Road'>5k Road</option>
                    <option value='withoutHours|10k Road'>10k Road</option>
                    <option value='withHours|H Marathon'>H Marathon</option>
                     <option value='withHours|Marathon'>Marathon</option>
                      <option value='withoutHours|3k S/Chase'>3k S/Chase</option>
                       <option value='withoutMinutes|110m Hurdles'>110m Hurdles</option>
                        <option value='withoutMinutes|400m Hurdles'>400m Hurdles</option>
                          <option value='withoutMinutes|60m (I)'>60m (I)</option>
                            <option value='withoutMinutes|60m Hurdles'>60m Hurdles</option>
				</select>
 
				<label>Distance:&nbsp;<input type="text" name="userDistance" size="10" class="timeData" readonly></label>	
</td>
  <td>
    
  </td>
  </tr>
    </table>
    <p><input type="button" name="Submit" value="OK" onClick="javascript: formget(this.form, 'http://www.runningprofiles.com/do5.php');"> 
    </p>
  </div>
   <div align="center">
   <div id="output" style="color: blue;">   </div>  </div>
</form>
 </fieldset>

Open in new window

0
runnerjp
Asked:
runnerjp
  • 7
  • 7
1 Solution
 
anoyesCommented:
Are you doing the validation with javascript?  If you do a return false; on your form's onSubmit action, then you can stop the form submission.  If you're doing JS validation, please post the code.  If not, where is the 'error' coming from?
0
 
runnerjpAuthor Commented:
ll sorry the coe would help wouldnt it lol

function limitText(limitField, limitNum) {
    if (limitField.value.length > limitNum) {
        limitField.value = limitField.value.substring(0, limitNum);
    } 
}
 
  var divid = 'output';  
 var loadingmessage = 'Processing...';  
   
 function AJAX(){  
    
 var xmlHttp;  
  try{  
  xmlHttp=new XMLHttpRequest(); // Firefox, Opera 8.0+, Safari  
  return xmlHttp;  
  }  
  catch (e){  
  try{  
  xmlHttp=new ActiveXObject("Msxml2.XMLHTTP"); // Internet Explorer  
  return xmlHttp;  
  }  
  catch (e){  
  try{  
  xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");  
  return xmlHttp;  
  }  
  catch (e){  
  alert("Your browser does not support AJAX!");  
  return false;  
  }  
  }  
  }  
    
 }  
    
  function formget(f, url) {  
    
  var poststr = getFormValues(f);  
  postData(url, poststr);  
    
  }  
    
  function postData(url, parameters){  
    
  var xmlHttp = AJAX();  
    
  xmlHttp.onreadystatechange =  function(){  
  if(xmlHttp.readyState > 0 && xmlHttp.readyState < 4){  
  document.getElementById(divid).innerHTML=loadingmessage;  
  }  
 if (xmlHttp.readyState == 4) {  
   
 document.getElementById(divid).innerHTML=xmlHttp.responseText;  
 
 }   
    
  }  
  xmlHttp.open("POST", url, true);  
  xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");  
 xmlHttp.setRequestHeader("Content-length", parameters.length);  
 xmlHttp.setRequestHeader("Connection", "close");  
   xmlHttp.send(parameters);  
 }  
    
 function getFormValues(fobj)  
    
 {  
  var str = "";  
  var valueArr = null;  
 var val = "";  
 var cmd = "";  
   
 for(var i = 0;i < fobj.elements.length;i++)  
   
 {  
switch(fobj.elements[i].type)  
  
 {  
 case "text":  
   
 str += fobj.elements[i].name +  
 "=" + escape(fobj.elements[i].value) + "&";  
 break;  
  case "textarea":
 
                   str += fobj.elements[i].name +
                    "=" + escape(fobj.elements[i].value) + "&";
                    break;
 case "select-one":  
   
str += fobj.elements[i].name +  
   "=" + fobj.elements[i].options[fobj.elements[i].selectedIndex].value + "&";  
  break;  
   
  }  
 }  
   
 str = str.substr(0,(str.length - 1));  
 return str;  
   
 }  
   
 //-->
 
        function checkit(which) {
var tim = which.value;
var flag = 0;
var flag2 = 0;
if (!/^\d{1,2}[-:\.]\d{2}/.test(tim)) {  // basic format
flag = 1;
}
tim = tim.replace(/[-\.]/g,":");
tim = tim.split(/:/);
if ((tim[0] > 23) || tim[1] > 59) {  // hour or minute values too great
flag = 1;
}
 
if (!/^[0-5]?[0-9].[0-5]?[0-9]$/.test(tim))  // basic format
flag2 = 1;
 
if ( flag != 0 && flag2 != 0 ) {
alert ("This field requires a valid time!" );
which.value = "";
which.focus();
return false;
}
		}
	function validateTime(nDistance){
 
		var useDistance = nDistance.split("|");
		var valid = true;
		var nTimeField = document.forms[0]['userDistance'];
		var nTime = document.forms[0]['userDistance'].value;
		if (useDistance[0] == "withHours")
				{
				 if (nTime == "")
					{
					 return; 
					}				
				 if (!/^\d{1,2}[:\-]\d{1,2}[:\-]\d{1,2}$/.test(nTime)
					 &&  !/^\d{1,2}[:\-]\d{1,2}[:\-]\d{1,2}\.\d{1,2}$/.test(nTime))
					{
					 alert('Hours, Minutes and Seconds must be separated\n' +
						'by a : (colon) or, - (hyphen) \n' +
						'Seconds may be expressed in tenths or hundreths:\n' +
						'ss.ss or, s.ss or, s.s or, ss.s');	
					 return;						 						
					}
				 nTime = nTime.replace(/[:\-]/g, "|").split("|");				 
				 nTime[0] > 23 ? valid = false : 
				 nTime[1] > 59 ? valid = false : 
				 nTime[2] > 59.99 ? valid = false : null; 					 
				 if (!valid)
					{
					 alert('Invalid time');
					 nTimeField.value = "";
					 nTimeField.focus();					 					 
					}				
				}
			if (useDistance[0] == "withoutHours")
				{	
				 if (nTime == "")
					{
					 return; 
					}				
				 if (!/^\d{1,2}[:\-]\d{1,2}$/.test(nTime)
					 &&  !/^\d{1,2}[:\-]\d{1,2}\.\d{1,2}$/.test(nTime))
					{
					 alert('Minutes and Seconds must be separated\n' +
						'by a : (colon) or, - (hyphen) \n' +
						'Seconds may be expressed in tenths or hundreths:\n' +
						'ss.ss or, s.ss or, s.s or, ss.s');	
					 return;						 						
					}
				 nTime = nTime.replace(/[:\-]/g, "|").split("|");
				 nTime[0] > 59 ? valid = false : 
				 nTime[1] > 59.99 ? valid = false : null; 					 
				 if (!valid)
					{
					 alert('Invalid time');
					 nTimeField.value = "";
					 nTimeField.focus();					 
					}
				}				
			if (useDistance[0] == "withoutMinutes")
				{					 	
				 if (nTime == "")
					{
					 return; 
					}				
				 if (!/^\d{1,2}$/.test(nTime)
					 &&  !/^\d{1,2}\.\d{1,2}$/.test(nTime))
					{
					 alert('Seconds may be expressed in tenths or hundreths:\n' +
						'ss.ss or, s.ss or, s.s or, ss.s');	
					 return;						 						
					}
				 nTime = nTime.replace(/[:\-]/g, "|").split("|");
				 nTime[0] > 59.99 ? valid = false : null; 					 
				 if (!valid)
					{
					 alert('Invalid time');
					 nTimeField.value = "";
					 nTimeField.focus();					 
					}
				}	
	}
 
	function setDistance(nDistance){
 
		var useDistance = nDistance.split("|");
		var nTimeField = document.forms[0]['userDistance'];
		nTimeField.value = "";
		document.forms[0]['userDistance'].parentNode.firstChild.data = useDistance[1] + ": ";		
		if (useDistance[0] == "#")
			{		
			 nTimeField.readOnly = true;			 
			 return;
			}
		nTimeField.readOnly = false; 					
	}
 
	function init(){
 
		document.forms[0]['userDistance'].onblur = function()
			{
			 validateTime(document.forms[0]['distance'].value);
			}		
	}
 
	navigator.appName == "Microsoft Internet Explorer" ? attachEvent('onload', init, false) : addEventListener('load', init, false);	

Open in new window

0
 
anoyesCommented:
Ok I think this'll work. I changed your validateTime function to return true and false rather than just return, and tweaked your formget function to check the time field before it tries to do the post.

function formget(f, url) {  
    if(validateTime(document.forms[0]['distance'].value))
    {
      var poststr = getFormValues(f);  
      postData(url, poststr);  
    }
  }  
 
	function validateTime(nDistance){
 
		var useDistance = nDistance.split("|");
		var valid = true;
		var nTimeField = document.forms[0]['userDistance'];
		var nTime = document.forms[0]['userDistance'].value;
		if (useDistance[0] == "withHours")
				{
				 if (nTime == "")
					{
					 return false; 
					}				
				 if (!/^\d{1,2}[:\-]\d{1,2}[:\-]\d{1,2}$/.test(nTime)
					 &&  !/^\d{1,2}[:\-]\d{1,2}[:\-]\d{1,2}\.\d{1,2}$/.test(nTime))
					{
					 alert('Hours, Minutes and Seconds must be separated\n' +
						'by a : (colon) or, - (hyphen) \n' +
						'Seconds may be expressed in tenths or hundreths:\n' +
						'ss.ss or, s.ss or, s.s or, ss.s');	
					 return false;						 						
					}
				 nTime = nTime.replace(/[:\-]/g, "|").split("|");				 
				 nTime[0] > 23 ? valid = false : 
				 nTime[1] > 59 ? valid = false : 
				 nTime[2] > 59.99 ? valid = false : null; 					 
				 if (!valid)
					{
					 alert('Invalid time');
					 nTimeField.value = "";
					 nTimeField.focus();					 					 
					}				
				}
			if (useDistance[0] == "withoutHours")
				{	
				 if (nTime == "")
					{
					 return false; 
					}				
				 if (!/^\d{1,2}[:\-]\d{1,2}$/.test(nTime)
					 &&  !/^\d{1,2}[:\-]\d{1,2}\.\d{1,2}$/.test(nTime))
					{
					 alert('Minutes and Seconds must be separated\n' +
						'by a : (colon) or, - (hyphen) \n' +
						'Seconds may be expressed in tenths or hundreths:\n' +
						'ss.ss or, s.ss or, s.s or, ss.s');	
					 return false;						 						
					}
				 nTime = nTime.replace(/[:\-]/g, "|").split("|");
				 nTime[0] > 59 ? valid = false : 
				 nTime[1] > 59.99 ? valid = false : null; 					 
				 if (!valid)
					{
					 alert('Invalid time');
					 nTimeField.value = "";
					 nTimeField.focus();					 
					}
				}				
			if (useDistance[0] == "withoutMinutes")
				{					 	
				 if (nTime == "")
					{
					 return false; 
					}				
				 if (!/^\d{1,2}$/.test(nTime)
					 &&  !/^\d{1,2}\.\d{1,2}$/.test(nTime))
					{
					 alert('Seconds may be expressed in tenths or hundreths:\n' +
						'ss.ss or, s.ss or, s.s or, ss.s');	
					 return false;						 						
					}
				 nTime = nTime.replace(/[:\-]/g, "|").split("|");
				 nTime[0] > 59.99 ? valid = false : null; 					 
				 if (!valid)
					{
					 alert('Invalid time');
					 nTimeField.value = "";
					 nTimeField.focus();					 
					}
				}
				return true;	
	}

Open in new window

0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
runnerjpAuthor Commented:
i used it like below and it wont let me enter anything at all into the textbox

function limitText(limitField, limitNum) {
    if (limitField.value.length > limitNum) {
        limitField.value = limitField.value.substring(0, limitNum);
    } 
}
 
  var divid = 'output';  
 var loadingmessage = 'Processing...';  
   
 function AJAX(){  
    
 var xmlHttp;  
  try{  
  xmlHttp=new XMLHttpRequest(); // Firefox, Opera 8.0+, Safari  
  return xmlHttp;  
  }  
  catch (e){  
  try{  
  xmlHttp=new ActiveXObject("Msxml2.XMLHTTP"); // Internet Explorer  
  return xmlHttp;  
  }  
  catch (e){  
  try{  
  xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");  
  return xmlHttp;  
  }  
  catch (e){  
  alert("Your browser does not support AJAX!");  
  return false;  
  }  
  }  
  }  
    
 }  
    
  function formget(f, url) {  
    
  var poststr = getFormValues(f);  
  postData(url, poststr);  
    
  }  
    
  function postData(url, parameters){  
    
  var xmlHttp = AJAX();  
    
  xmlHttp.onreadystatechange =  function(){  
  if(xmlHttp.readyState > 0 && xmlHttp.readyState < 4){  
  document.getElementById(divid).innerHTML=loadingmessage;  
  }  
 if (xmlHttp.readyState == 4) {  
   
 document.getElementById(divid).innerHTML=xmlHttp.responseText;  
 
 }   
    
  }  
  xmlHttp.open("POST", url, true);  
  xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");  
 xmlHttp.setRequestHeader("Content-length", parameters.length);  
 xmlHttp.setRequestHeader("Connection", "close");  
   xmlHttp.send(parameters);  
 }  
    
 function getFormValues(fobj)  
    
 {  
  var str = "";  
  var valueArr = null;  
 var val = "";  
 var cmd = "";  
   
 for(var i = 0;i < fobj.elements.length;i++)  
   
 {  
switch(fobj.elements[i].type)  
  
 {  
 case "text":  
   
 str += fobj.elements[i].name +  
 "=" + escape(fobj.elements[i].value) + "&";  
 break;  
  case "textarea":
 
                   str += fobj.elements[i].name +
                    "=" + escape(fobj.elements[i].value) + "&";
                    break;
 case "select-one":  
   
str += fobj.elements[i].name +  
   "=" + fobj.elements[i].options[fobj.elements[i].selectedIndex].value + "&";  
  break;  
   
  }  
 }  
   
 str = str.substr(0,(str.length - 1));  
 return str;  
   
 }  
   
 //-->
 
        function checkit(which) {
var tim = which.value;
var flag = 0;
var flag2 = 0;
if (!/^\d{1,2}[-:\.]\d{2}/.test(tim)) {  // basic format
flag = 1;
}
tim = tim.replace(/[-\.]/g,":");
tim = tim.split(/:/);
if ((tim[0] > 23) || tim[1] > 59) {  // hour or minute values too great
flag = 1;
}
 
if (!/^[0-5]?[0-9].[0-5]?[0-9]$/.test(tim))  // basic format
flag2 = 1;
 
if ( flag != 0 && flag2 != 0 ) {
alert ("This field requires a valid time!" );
which.value = "";
which.focus();
return false;
}
		}
 if(validateTime(document.forms[0]['distance'].value))
    {
      var poststr = getFormValues(f);  
      postData(url, poststr);  
    }
  }  
 
	function validateTime(nDistance){
 
		var useDistance = nDistance.split("|");
		var valid = true;
		var nTimeField = document.forms[0]['userDistance'];
		var nTime = document.forms[0]['userDistance'].value;
		if (useDistance[0] == "withHours")
				{
				 if (nTime == "")
					{
					 return false; 
					}				
				 if (!/^\d{1,2}[:\-]\d{1,2}[:\-]\d{1,2}$/.test(nTime)
					 &&  !/^\d{1,2}[:\-]\d{1,2}[:\-]\d{1,2}\.\d{1,2}$/.test(nTime))
					{
					 alert('Hours, Minutes and Seconds must be separated\n' +
						'by a : (colon) or, - (hyphen) \n' +
						'Seconds may be expressed in tenths or hundreths:\n' +
						'ss.ss or, s.ss or, s.s or, ss.s');	
					 return false;						 						
					}
				 nTime = nTime.replace(/[:\-]/g, "|").split("|");				 
				 nTime[0] > 23 ? valid = false : 
				 nTime[1] > 59 ? valid = false : 
				 nTime[2] > 59.99 ? valid = false : null; 					 
				 if (!valid)
					{
					 alert('Invalid time');
					 nTimeField.value = "";
					 nTimeField.focus();					 					 
					}				
				}
			if (useDistance[0] == "withoutHours")
				{	
				 if (nTime == "")
					{
					 return false; 
					}				
				 if (!/^\d{1,2}[:\-]\d{1,2}$/.test(nTime)
					 &&  !/^\d{1,2}[:\-]\d{1,2}\.\d{1,2}$/.test(nTime))
					{
					 alert('Minutes and Seconds must be separated\n' +
						'by a : (colon) or, - (hyphen) \n' +
						'Seconds may be expressed in tenths or hundreths:\n' +
						'ss.ss or, s.ss or, s.s or, ss.s');	
					 return false;						 						
					}
				 nTime = nTime.replace(/[:\-]/g, "|").split("|");
				 nTime[0] > 59 ? valid = false : 
				 nTime[1] > 59.99 ? valid = false : null; 					 
				 if (!valid)
					{
					 alert('Invalid time');
					 nTimeField.value = "";
					 nTimeField.focus();					 
					}
				}				
			if (useDistance[0] == "withoutMinutes")
				{					 	
				 if (nTime == "")
					{
					 return false; 
					}				
				 if (!/^\d{1,2}$/.test(nTime)
					 &&  !/^\d{1,2}\.\d{1,2}$/.test(nTime))
					{
					 alert('Seconds may be expressed in tenths or hundreths:\n' +
						'ss.ss or, s.ss or, s.s or, ss.s');	
					 return false;						 						
					}
				 nTime = nTime.replace(/[:\-]/g, "|").split("|");
				 nTime[0] > 59.99 ? valid = false : null; 					 
				 if (!valid)
					{
					 alert('Invalid time');
					 nTimeField.value = "";
					 nTimeField.focus();					 
					}
				}
				return true;	
	}
 
 
	function setDistance(nDistance){
 
		var useDistance = nDistance.split("|");
		var nTimeField = document.forms[0]['userDistance'];
		nTimeField.value = "";
		document.forms[0]['userDistance'].parentNode.firstChild.data = useDistance[1] + ": ";		
		if (useDistance[0] == "#")
			{		
			 nTimeField.readOnly = true;			 
			 return;
			}
		nTimeField.readOnly = false; 					
	}
 
	function init(){
 
		document.forms[0]['userDistance'].onblur = function()
			{
			 validateTime(document.forms[0]['distance'].value);
			}		
	}
 
	navigator.appName == "Microsoft Internet Explorer" ? attachEvent('onload', init, false) : addEventListener('load', init, false);	

Open in new window

0
 
runnerjpAuthor Commented:
i used it like below and it wont let me enter anything at all into the textbox

function limitText(limitField, limitNum) {
    if (limitField.value.length > limitNum) {
        limitField.value = limitField.value.substring(0, limitNum);
    } 
}
 
  var divid = 'output';  
 var loadingmessage = 'Processing...';  
   
 function AJAX(){  
    
 var xmlHttp;  
  try{  
  xmlHttp=new XMLHttpRequest(); // Firefox, Opera 8.0+, Safari  
  return xmlHttp;  
  }  
  catch (e){  
  try{  
  xmlHttp=new ActiveXObject("Msxml2.XMLHTTP"); // Internet Explorer  
  return xmlHttp;  
  }  
  catch (e){  
  try{  
  xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");  
  return xmlHttp;  
  }  
  catch (e){  
  alert("Your browser does not support AJAX!");  
  return false;  
  }  
  }  
  }  
    
 }  
    
  function formget(f, url) {  
    
  var poststr = getFormValues(f);  
  postData(url, poststr);  
    
  }  
    
  function postData(url, parameters){  
    
  var xmlHttp = AJAX();  
    
  xmlHttp.onreadystatechange =  function(){  
  if(xmlHttp.readyState > 0 && xmlHttp.readyState < 4){  
  document.getElementById(divid).innerHTML=loadingmessage;  
  }  
 if (xmlHttp.readyState == 4) {  
   
 document.getElementById(divid).innerHTML=xmlHttp.responseText;  
 
 }   
    
  }  
  xmlHttp.open("POST", url, true);  
  xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");  
 xmlHttp.setRequestHeader("Content-length", parameters.length);  
 xmlHttp.setRequestHeader("Connection", "close");  
   xmlHttp.send(parameters);  
 }  
    
 function getFormValues(fobj)  
    
 {  
  var str = "";  
  var valueArr = null;  
 var val = "";  
 var cmd = "";  
   
 for(var i = 0;i < fobj.elements.length;i++)  
   
 {  
switch(fobj.elements[i].type)  
  
 {  
 case "text":  
   
 str += fobj.elements[i].name +  
 "=" + escape(fobj.elements[i].value) + "&";  
 break;  
  case "textarea":
 
                   str += fobj.elements[i].name +
                    "=" + escape(fobj.elements[i].value) + "&";
                    break;
 case "select-one":  
   
str += fobj.elements[i].name +  
   "=" + fobj.elements[i].options[fobj.elements[i].selectedIndex].value + "&";  
  break;  
   
  }  
 }  
   
 str = str.substr(0,(str.length - 1));  
 return str;  
   
 }  
   
 //-->
 
        function checkit(which) {
var tim = which.value;
var flag = 0;
var flag2 = 0;
if (!/^\d{1,2}[-:\.]\d{2}/.test(tim)) {  // basic format
flag = 1;
}
tim = tim.replace(/[-\.]/g,":");
tim = tim.split(/:/);
if ((tim[0] > 23) || tim[1] > 59) {  // hour or minute values too great
flag = 1;
}
 
if (!/^[0-5]?[0-9].[0-5]?[0-9]$/.test(tim))  // basic format
flag2 = 1;
 
if ( flag != 0 && flag2 != 0 ) {
alert ("This field requires a valid time!" );
which.value = "";
which.focus();
return false;
}
		}
 if(validateTime(document.forms[0]['distance'].value))
    {
      var poststr = getFormValues(f);  
      postData(url, poststr);  
    }
  }  
 
	function validateTime(nDistance){
 
		var useDistance = nDistance.split("|");
		var valid = true;
		var nTimeField = document.forms[0]['userDistance'];
		var nTime = document.forms[0]['userDistance'].value;
		if (useDistance[0] == "withHours")
				{
				 if (nTime == "")
					{
					 return false; 
					}				
				 if (!/^\d{1,2}[:\-]\d{1,2}[:\-]\d{1,2}$/.test(nTime)
					 &&  !/^\d{1,2}[:\-]\d{1,2}[:\-]\d{1,2}\.\d{1,2}$/.test(nTime))
					{
					 alert('Hours, Minutes and Seconds must be separated\n' +
						'by a : (colon) or, - (hyphen) \n' +
						'Seconds may be expressed in tenths or hundreths:\n' +
						'ss.ss or, s.ss or, s.s or, ss.s');	
					 return false;						 						
					}
				 nTime = nTime.replace(/[:\-]/g, "|").split("|");				 
				 nTime[0] > 23 ? valid = false : 
				 nTime[1] > 59 ? valid = false : 
				 nTime[2] > 59.99 ? valid = false : null; 					 
				 if (!valid)
					{
					 alert('Invalid time');
					 nTimeField.value = "";
					 nTimeField.focus();					 					 
					}				
				}
			if (useDistance[0] == "withoutHours")
				{	
				 if (nTime == "")
					{
					 return false; 
					}				
				 if (!/^\d{1,2}[:\-]\d{1,2}$/.test(nTime)
					 &&  !/^\d{1,2}[:\-]\d{1,2}\.\d{1,2}$/.test(nTime))
					{
					 alert('Minutes and Seconds must be separated\n' +
						'by a : (colon) or, - (hyphen) \n' +
						'Seconds may be expressed in tenths or hundreths:\n' +
						'ss.ss or, s.ss or, s.s or, ss.s');	
					 return false;						 						
					}
				 nTime = nTime.replace(/[:\-]/g, "|").split("|");
				 nTime[0] > 59 ? valid = false : 
				 nTime[1] > 59.99 ? valid = false : null; 					 
				 if (!valid)
					{
					 alert('Invalid time');
					 nTimeField.value = "";
					 nTimeField.focus();					 
					}
				}				
			if (useDistance[0] == "withoutMinutes")
				{					 	
				 if (nTime == "")
					{
					 return false; 
					}				
				 if (!/^\d{1,2}$/.test(nTime)
					 &&  !/^\d{1,2}\.\d{1,2}$/.test(nTime))
					{
					 alert('Seconds may be expressed in tenths or hundreths:\n' +
						'ss.ss or, s.ss or, s.s or, ss.s');	
					 return false;						 						
					}
				 nTime = nTime.replace(/[:\-]/g, "|").split("|");
				 nTime[0] > 59.99 ? valid = false : null; 					 
				 if (!valid)
					{
					 alert('Invalid time');
					 nTimeField.value = "";
					 nTimeField.focus();					 
					}
				}
				return true;	
	}
 
 
	function setDistance(nDistance){
 
		var useDistance = nDistance.split("|");
		var nTimeField = document.forms[0]['userDistance'];
		nTimeField.value = "";
		document.forms[0]['userDistance'].parentNode.firstChild.data = useDistance[1] + ": ";		
		if (useDistance[0] == "#")
			{		
			 nTimeField.readOnly = true;			 
			 return;
			}
		nTimeField.readOnly = false; 					
	}
 
	function init(){
 
		document.forms[0]['userDistance'].onblur = function()
			{
			 validateTime(document.forms[0]['distance'].value);
			}		
	}
 
	navigator.appName == "Microsoft Internet Explorer" ? attachEvent('onload', init, false) : addEventListener('load', init, false);	

Open in new window

0
 
anoyesCommented:
There were some problems with brackets.  Should be all set now.  For future reference, I'd highly advise getting either the Web Developer or Firebug plugins for Firefox (if you're using it) - they do a great job of helping debug javascript.

<script type="text/javascript">
function limitText(limitField, limitNum) {
    if (limitField.value.length > limitNum) {
        limitField.value = limitField.value.substring(0, limitNum);
    } 
}
 
var divid = 'output';  
var loadingmessage = 'Processing...';  
   
function AJAX(){      
  var xmlHttp;  
  try{  
    xmlHttp=new XMLHttpRequest(); // Firefox, Opera 8.0+, Safari  
    return xmlHttp;  
  }  
  catch (e){  
    try{
      xmlHttp=new ActiveXObject("Msxml2.XMLHTTP"); // Internet Explorer  
      return xmlHttp;  
    }  
    catch (e){  
      try{  
        xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");  
        return xmlHttp;  
      }  
      catch (e){  
        alert("Your browser does not support AJAX!");  
        return false;  
      }  
    }  
  }
}  
    
function formget(f, url) {
  var poststr = getFormValues(f);  
  postData(url, poststr);
}  
    
function postData(url, parameters){
  var xmlHttp = AJAX();  
    
  xmlHttp.onreadystatechange =  function(){  
    if(xmlHttp.readyState > 0 && xmlHttp.readyState < 4){  
      document.getElementById(divid).innerHTML=loadingmessage;  
    }  
    if (xmlHttp.readyState == 4) {  
      document.getElementById(divid).innerHTML=xmlHttp.responseText;
    }
  }
  xmlHttp.open("POST", url, true);  
  xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");  
  xmlHttp.setRequestHeader("Content-length", parameters.length);  
  xmlHttp.setRequestHeader("Connection", "close");  
  xmlHttp.send(parameters);  
}  
    
function getFormValues(fobj) {
  var str = "";  
  var valueArr = null;  
  var val = "";  
  var cmd = "";  
   
  for(var i = 0;i < fobj.elements.length;i++) {  
    switch(fobj.elements[i].type) {  
      case "text":  
        str += fobj.elements[i].name +  
        "=" + escape(fobj.elements[i].value) + "&";  
        break;  
      case "textarea":
        str += fobj.elements[i].name +
        "=" + escape(fobj.elements[i].value) + "&";
        break;
      case "select-one":  
        str += fobj.elements[i].name +  
        "=" + fobj.elements[i].options[fobj.elements[i].selectedIndex].value + "&";  
        break;
    }
  }
  str = str.substr(0,(str.length - 1));  
  return str;
}  
   
 //-->
 
function checkit(which) {
  var tim = which.value;
  var flag = 0;
  var flag2 = 0;
  
  if (!/^\d{1,2}[-:\.]\d{2}/.test(tim)) {  // basic format
    flag = 1;
  }
  
  tim = tim.replace(/[-\.]/g,":");
  tim = tim.split(/:/);
  
  if ((tim[0] > 23) || tim[1] > 59) {  // hour or minute values too great
    flag = 1;
  }
 
  if (!/^[0-5]?[0-9].[0-5]?[0-9]$/.test(tim))  // basic format
    flag2 = 1;
 
  if ( flag != 0 && flag2 != 0 ) {
    alert ("This field requires a valid time!" );
    which.value = "";
    which.focus();
    return false;
  }
  if(validateTime(document.forms[0]['distance'].value)) {
    var poststr = getFormValues(f);  
    postData(url, poststr);  
  }
}  
 
function validateTime(nDistance) {
  var useDistance = nDistance.split("|");
  var valid = true;
  var nTimeField = document.forms[0]['userDistance'];
  var nTime = document.forms[0]['userDistance'].value;
  
  if (useDistance[0] == "withHours")
  {
    if (nTime == "")
    {
      return false; 
    }				
    if (!/^\d{1,2}[:\-]\d{1,2}[:\-]\d{1,2}$/.test(nTime)
      &&  !/^\d{1,2}[:\-]\d{1,2}[:\-]\d{1,2}\.\d{1,2}$/.test(nTime))
    {
      alert('Hours, Minutes and Seconds must be separated\n' +
      'by a : (colon) or, - (hyphen) \n' +
      'Seconds may be expressed in tenths or hundreths:\n' +
      'ss.ss or, s.ss or, s.s or, ss.s');	
      return false;						 						
    }
    
    nTime = nTime.replace(/[:\-]/g, "|").split("|");				 
    nTime[0] > 23 ? valid = false : 
    nTime[1] > 59 ? valid = false : 
    nTime[2] > 59.99 ? valid = false : null;
    					 
    if (!valid) {
      alert('Invalid time');
      nTimeField.value = "";
      nTimeField.focus();					 					 
    }
  }
			if (useDistance[0] == "withoutHours")
				{	
				 if (nTime == "")
					{
					 return false; 
					}				
				 if (!/^\d{1,2}[:\-]\d{1,2}$/.test(nTime)
					 &&  !/^\d{1,2}[:\-]\d{1,2}\.\d{1,2}$/.test(nTime))
					{
					 alert('Minutes and Seconds must be separated\n' +
						'by a : (colon) or, - (hyphen) \n' +
						'Seconds may be expressed in tenths or hundreths:\n' +
						'ss.ss or, s.ss or, s.s or, ss.s');	
					 return false;						 						
					}
				 nTime = nTime.replace(/[:\-]/g, "|").split("|");
				 nTime[0] > 59 ? valid = false : 
				 nTime[1] > 59.99 ? valid = false : null; 					 
				 if (!valid)
					{
					 alert('Invalid time');
					 nTimeField.value = "";
					 nTimeField.focus();					 
					}
				}				
			if (useDistance[0] == "withoutMinutes")
				{					 	
				 if (nTime == "")
					{
					 return false; 
					}				
				 if (!/^\d{1,2}$/.test(nTime)
					 &&  !/^\d{1,2}\.\d{1,2}$/.test(nTime))
					{
					 alert('Seconds may be expressed in tenths or hundreths:\n' +
						'ss.ss or, s.ss or, s.s or, ss.s');	
					 return false;						 						
					}
				 nTime = nTime.replace(/[:\-]/g, "|").split("|");
				 nTime[0] > 59.99 ? valid = false : null; 					 
				 if (!valid)
					{
					 alert('Invalid time');
					 nTimeField.value = "";
					 nTimeField.focus();					 
					}
				}
				return true;	
	}
 
 
	function setDistance(nDistance){
 
		var useDistance = nDistance.split("|");
		var nTimeField = document.forms[0]['userDistance'];
		nTimeField.value = "";
		document.forms[0]['userDistance'].parentNode.firstChild.data = useDistance[1] + ": ";		
		if (useDistance[0] == "#")
			{		
			 nTimeField.readOnly = true;			 
			 return;
			}
		nTimeField.readOnly = false; 					
	}
 
	function init(){
 
		document.forms[0]['userDistance'].onblur = function()
			{
			 validateTime(document.forms[0]['distance'].value);
			}		
	}
 
	navigator.appName == "Microsoft Internet Explorer" ? attachEvent('onload', init, false) : addEventListener('load', init, false);	
 
</script>

Open in new window

0
 
runnerjpAuthor Commented:
i copied and pasted the above code but it dosnt let me add any text into the textbox :S
0
 
anoyesCommented:
Hmm, I see the problem in IE, but I can enter a value once I select a distance from the drop down.  Is this page available somewhere where I can look at it on your site, b/c aside from that issue in IE it seems to be working fine for me locally.
0
 
runnerjpAuthor Commented:
0
 
anoyesCommented:
OK, it seems to be behaving the same there, and the reason why is that you have the readonly attribute set on the text box, and only remove that attribute when the drop down list is changed to something other than 'Select the distance'.  Are you unable to enter a value regardless of what the selection in the drop down list is?  If so, what browser & version are you using?
0
 
runnerjpAuthor Commented:
sorry try it again as i didnt have right code uploaded when u viewed it... the readonly is to make sure users select there distance...

i have firefox 3 & internet explorer.... the new code wont change the read only bascily
0
 
anoyesCommented:
Ah, Ok.  If you're using an external JS file, you don't need to wrap the file in a <script> block.  So your external js file should just be the code.
0
 
runnerjpAuthor Commented:
ah yes :).... i have used script (below) and it still lets me submit the data once the ox has been shown sadly :(
function limitText(limitField, limitNum) {
    if (limitField.value.length > limitNum) {
        limitField.value = limitField.value.substring(0, limitNum);
    } 
}
 
var divid = 'output';  
var loadingmessage = 'Processing...';  
   
function AJAX(){      
  var xmlHttp;  
  try{  
    xmlHttp=new XMLHttpRequest(); // Firefox, Opera 8.0+, Safari  
    return xmlHttp;  
  }  
  catch (e){  
    try{
      xmlHttp=new ActiveXObject("Msxml2.XMLHTTP"); // Internet Explorer  
      return xmlHttp;  
    }  
    catch (e){  
      try{  
        xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");  
        return xmlHttp;  
      }  
      catch (e){  
        alert("Your browser does not support AJAX!");  
        return false;  
      }  
    }  
  }
}  
    
function formget(f, url) {
  var poststr = getFormValues(f);  
  postData(url, poststr);
}  
    
function postData(url, parameters){
  var xmlHttp = AJAX();  
    
  xmlHttp.onreadystatechange =  function(){  
    if(xmlHttp.readyState > 0 && xmlHttp.readyState < 4){  
      document.getElementById(divid).innerHTML=loadingmessage;  
    }  
    if (xmlHttp.readyState == 4) {  
      document.getElementById(divid).innerHTML=xmlHttp.responseText;
    }
  }
  xmlHttp.open("POST", url, true);  
  xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");  
  xmlHttp.setRequestHeader("Content-length", parameters.length);  
  xmlHttp.setRequestHeader("Connection", "close");  
  xmlHttp.send(parameters);  
}  
    
function getFormValues(fobj) {
  var str = "";  
  var valueArr = null;  
  var val = "";  
  var cmd = "";  
   
  for(var i = 0;i < fobj.elements.length;i++) {  
    switch(fobj.elements[i].type) {  
      case "text":  
        str += fobj.elements[i].name +  
        "=" + escape(fobj.elements[i].value) + "&";  
        break;  
      case "textarea":
        str += fobj.elements[i].name +
        "=" + escape(fobj.elements[i].value) + "&";
        break;
      case "select-one":  
        str += fobj.elements[i].name +  
        "=" + fobj.elements[i].options[fobj.elements[i].selectedIndex].value + "&";  
        break;
    }
  }
  str = str.substr(0,(str.length - 1));  
  return str;
}  
   
 //-->
 
function checkit(which) {
  var tim = which.value;
  var flag = 0;
  var flag2 = 0;
  
  if (!/^\d{1,2}[-:\.]\d{2}/.test(tim)) {  // basic format
    flag = 1;
  }
  
  tim = tim.replace(/[-\.]/g,":");
  tim = tim.split(/:/);
  
  if ((tim[0] > 23) || tim[1] > 59) {  // hour or minute values too great
    flag = 1;
  }
 
  if (!/^[0-5]?[0-9].[0-5]?[0-9]$/.test(tim))  // basic format
    flag2 = 1;
 
  if ( flag != 0 && flag2 != 0 ) {
    alert ("This field requires a valid time!" );
    which.value = "";
    which.focus();
    return false;
  }
  if(validateTime(document.forms[0]['distance'].value)) {
    var poststr = getFormValues(f);  
    postData(url, poststr);  
  }
}  
 
function validateTime(nDistance) {
  var useDistance = nDistance.split("|");
  var valid = true;
  var nTimeField = document.forms[0]['userDistance'];
  var nTime = document.forms[0]['userDistance'].value;
  
  if (useDistance[0] == "withHours")
  {
    if (nTime == "")
    {
      return false; 
    }				
    if (!/^\d{1,2}[:\-]\d{1,2}[:\-]\d{1,2}$/.test(nTime)
      &&  !/^\d{1,2}[:\-]\d{1,2}[:\-]\d{1,2}\.\d{1,2}$/.test(nTime))
    {
      alert('Hours, Minutes and Seconds must be separated\n' +
      'by a : (colon) or, - (hyphen) \n' +
      'Seconds may be expressed in tenths or hundreths:\n' +
      'ss.ss or, s.ss or, s.s or, ss.s');	
      return false;						 						
    }
    
    nTime = nTime.replace(/[:\-]/g, "|").split("|");				 
    nTime[0] > 23 ? valid = false : 
    nTime[1] > 59 ? valid = false : 
    nTime[2] > 59.99 ? valid = false : null;
    					 
    if (!valid) {
      alert('Invalid time');
      nTimeField.value = "";
      nTimeField.focus();					 					 
    }
  }
			if (useDistance[0] == "withoutHours")
				{	
				 if (nTime == "")
					{
					 return false; 
					}				
				 if (!/^\d{1,2}[:\-]\d{1,2}$/.test(nTime)
					 &&  !/^\d{1,2}[:\-]\d{1,2}\.\d{1,2}$/.test(nTime))
					{
					 alert('Minutes and Seconds must be separated\n' +
						'by a : (colon) or, - (hyphen) \n' +
						'Seconds may be expressed in tenths or hundreths:\n' +
						'ss.ss or, s.ss or, s.s or, ss.s');	
					 return false;						 						
					}
				 nTime = nTime.replace(/[:\-]/g, "|").split("|");
				 nTime[0] > 59 ? valid = false : 
				 nTime[1] > 59.99 ? valid = false : null; 					 
				 if (!valid)
					{
					 alert('Invalid time');
					 nTimeField.value = "";
					 nTimeField.focus();					 
					}
				}				
			if (useDistance[0] == "withoutMinutes")
				{					 	
				 if (nTime == "")
					{
					 return false; 
					}				
				 if (!/^\d{1,2}$/.test(nTime)
					 &&  !/^\d{1,2}\.\d{1,2}$/.test(nTime))
					{
					 alert('Seconds may be expressed in tenths or hundreths:\n' +
						'ss.ss or, s.ss or, s.s or, ss.s');	
					 return false;						 						
					}
				 nTime = nTime.replace(/[:\-]/g, "|").split("|");
				 nTime[0] > 59.99 ? valid = false : null; 					 
				 if (!valid)
					{
					 alert('Invalid time');
					 nTimeField.value = "";
					 nTimeField.focus();					 
					}
				}
				return true;	
	}
 
 
	function setDistance(nDistance){
 
		var useDistance = nDistance.split("|");
		var nTimeField = document.forms[0]['userDistance'];
		nTimeField.value = "";
		document.forms[0]['userDistance'].parentNode.firstChild.data = useDistance[1] + ": ";		
		if (useDistance[0] == "#")
			{		
			 nTimeField.readOnly = true;			 
			 return;
			}
		nTimeField.readOnly = false; 					
	}
 
	function init(){
 
		document.forms[0]['userDistance'].onblur = function()
			{
			 validateTime(document.forms[0]['distance'].value);
			}		
	}
 
	navigator.appName == "Microsoft Internet Explorer" ? attachEvent('onload', init, false) : addEventListener('load', init, false);	

Open in new window

0
 
anoyesCommented:
Sorry, I had modified the formget function a while back; changes must have gotten lost somewhere along the way.  Anywho, the formget function should look like this:

function formget(f, url) {  
    if(validateTime(document.forms[0]['distance'].value))
    {
      var poststr = getFormValues(f);  
      postData(url, poststr);  
    }
  } 

Open in new window

0
 
CWS (haripriya)Commented:
This question has been classified as abandoned and is closed as part of the Cleanup Program. See the recommendation for more details.
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 7
  • 7
Tackle projects and never again get stuck behind a technical roadblock.
Join Now