-
Im using Dreamweaver and I want to validate a field on one of my forms to see if its blank and return a little pop up error, my problem is... the pop up error contains the exact name of the field its checking, I want to make it display a custom name, is there any way to do this?
Thanks
-
not without actually knowing javascript - I doubt you could do it just with dreamweaver.
They way you'd do it is just run some if statements such as
IF fieldname = "Name"
errormessage .= "You forgot to insert your name dofus";
alert(errormessage);
Note: the above isn't correct syntax but you get the idea.
-
If it's different form fields you're checking, there's a good script for this that collects the names of empty fields, and displays one alert with the list of those fields. But it sounds like you might be trying to do something else, and for just one form field. I need more details on what you mean by a "custom name" and I could probably help you.
-
I think aspen is on the right track, lets say I have my field named "date_ent" instead of a pop up box saying "You forgot to fill in the "date_ent" field, I want it to say "Please go back and fill in the Date Entered field".....
-
A versatile solution is to use a combination of scripts to accomplish this. In your form tag, call a script to validate the form. This script checks the field, totals up all fields that don't validate, and displays an alert listing those fields. In this example, it calls a checkEmpty script, but there are also short scripts for checkURL, checkNumber, checkDate, etc. that can validate fields for the particular format you want. In your form tag, call the fucntion like this:
<form name="myForm" action="results.html" method="post" onSubmit="return validateForm(this);">
Code:
function validateForm(frm) {
checkEmpty(frm.date_ent, "Date Entered")
if (strBlanks != "" || strErrors != "")
{
strErrors = formErrorSentence(strBlanks, strErrors);
alert(strErrors);
strErrors = "";
strBlanks = "";
return false;
}
else
{
return true;
}
}
function checkEmpty(objField, strFieldDescription)
{
if (objField.value == "")
{
strBlanks += "\n" + strFieldDescription;
return false;
}
else
{
return true;
}
}
function formErrorSentence(strEmpty, strInvalid)
{
msg = "_____________________________________________________________________\n\n";
msg += "The request could not be carried out due to the following error(s).\n";
msg += "Please correct these error(s) and re-submit.\n";
msg += "_____________________________________________________________________\n\n";
msg += strInvalid;
if (strEmpty != "")
msg += "\n- The following required field(s) are empty:" + strEmpty;
return msg;
}
I hope this isn't confusing, it's really quite simple once you see what's going on. This may be overkill for what you're trying to do, but when you start to get into long forms, this is an efficient and easy way to validate.