SitePoint Sponsor

User Tag List

Results 1 to 5 of 5

Hybrid View

  1. #1
    SitePoint Enthusiast
    Join Date
    Mar 2001
    Posts
    34
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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

  2. #2
    Serial Publisher silver trophy aspen's Avatar
    Join Date
    Aug 1999
    Location
    East Lansing, MI USA
    Posts
    12,937
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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.
    Chris Beasley - I publish content and ecommerce sites.
    Featured Article: Free Comprehensive SEO Guide
    My Guide to Building a Successful Website
    My Blog|My Webmaster Forums

  3. #3
    I believe you have my stapler. scrubz's Avatar
    Join Date
    Feb 2001
    Location
    Van down by the river
    Posts
    254
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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.

  4. #4
    SitePoint Enthusiast
    Join Date
    Mar 2001
    Posts
    34
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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".....

  5. #5
    I believe you have my stapler. scrubz's Avatar
    Join Date
    Feb 2001
    Location
    Van down by the river
    Posts
    254
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •