View Full Version : Variables in paths

09-17-2005, 07:55 AM

Im kinda new to JavaScripting but I cant seem to find the answer to this anywer.

I have a function which checks to see if a date is in the dd/mm/yyyy format in a certain field. If it returns false, it alerts the user and is supposed to focus back to that field.

function DateValid(myDate, fieldName) {
if (testDate(myDate) == false){

Except that the fieldName variable, which is sent from the field via onBlur(), seems to stop it working... I think.

Any ideas?

09-17-2005, 03:57 PM
Welcome to codingforums!

Do you require something like this mate?
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Untitled Document</title>
<script type="text/javascript">
function checkDate(field) {
if(field.value == field.defaultValue) {
return false;

if(!/^\d{1,2}\/\d{1,2}\/\d{4}$/.test(field.value)) {
alert("invalid date supplied\nDate must be DD/MM/YYYY");
return false;
} else {
return true;

<form name="frm">
Enter date then click anywhere else to blur() the text box:
<br><input type="text" name="txtDate" onblur="checkDate(this);">
Hope this helps.


09-18-2005, 02:58 AM
Well, I already have all the date validation stuff set up, I just need to make it select the field if it returns false. But because I have numerous fields using the same function, I have to have the name of the field as a variable.

But if I make the path:

variable = 'DateCompleted';


It says that the field doesnt exist or is null. Because its looking for a field called 'variable' instead of one called 'DateCompleted'

If I make sense...

And thanks for the welcome Mn :)