Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Why won't this validation work? 1

Status
Not open for further replies.

LyndonOHRC

Programmer
Sep 8, 2005
603
US
I'm trying to have a select default to " " and validate that either of the other options are selected. But I can’t get it to trigger.

Any help appreciated.
Lyndon
Code:
<form  action="inserttrack.cfm" name="ReceiptForm" onsubmit="return (LicYear())">

 License Year: 
 <select name="LicenseYear">
  <option value="" selected>&nbsp;</option>
  <option value="2006">2006</option>
  <option value="2007">2007</option>
 </select>
 <input type="submit" value="Print Preview">
</form>

<script language="JavaScript" type="text/javascript"> 	
function LicYear(){
 if (document.ReceiptForm.LicenseYear.value.trim() == ""){
  alert('You Must Choose a License Year');
  document.ReceiptForm.LicenseYear.focus();
  return false
 }
}
</script>

Lyndon

---People Remember about 10% of what you say ---They never forget how you made them feel. Covey
 
In case anyone searches this topic here is the code I forgot to include:

Code:
String.prototype.trim = function() {return this.replace(/^\s+|\s+$/g, "");};

Lyndon

---People Remember about 10% of what you say ---They never forget how you made them feel. Covey
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top