Solved

If error shows delete textbox data...

Posted on 2009-03-29
16
264 Views
Last Modified: 2012-05-06
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
Comment
Question by:runnerjp
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 7
  • 7
16 Comments
 
LVL 16

Expert Comment

by:anoyes
ID: 24013762
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
 

Author Comment

by:runnerjp
ID: 24013943
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
 
LVL 16

Expert Comment

by:anoyes
ID: 24014134
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
PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

 

Author Comment

by:runnerjp
ID: 24017506
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
 

Author Comment

by:runnerjp
ID: 24017507
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
 
LVL 16

Expert Comment

by:anoyes
ID: 24025480
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
 

Author Comment

by:runnerjp
ID: 24038345
i copied and pasted the above code but it dosnt let me add any text into the textbox :S
0
 
LVL 16

Expert Comment

by:anoyes
ID: 24039245
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
 

Author Comment

by:runnerjp
ID: 24039359
0
 
LVL 16

Expert Comment

by:anoyes
ID: 24039429
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
 

Author Comment

by:runnerjp
ID: 24039793
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
 
LVL 16

Expert Comment

by:anoyes
ID: 24039907
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
 

Author Comment

by:runnerjp
ID: 24040179
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
 
LVL 16

Accepted Solution

by:
anoyes earned 500 total points
ID: 24040891
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
 
LVL 16

Expert Comment

by:CWS (haripriya)
ID: 37105788
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

Technology Partners: 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!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
SharePoint and CAML query help 4 23
HTML editor custom button 3 84
Change background images after 5 seconds. 12 44
Difference between Highcharts and Mapbox 10 43
Introduction A frequently asked question goes something like this:  "I am running a long process in the background and I want to alert my client when the process finishes.  How can I send a message to the browser?"  Unfortunately, the short answer…
Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…
Suggested Courses

739 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question