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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Highlight required fields

Status
Not open for further replies.

fergy1

IS-IT--Management
Jul 25, 2003
32
US
Hello-

What can I add to this to tell the script to highlight the input box in a different color? So it will alert them and change the color of the input box to red if not filled out?

if (theForm.pr_ny_estimate.value.length < 1)
{
alert("Please enter at least 1 characters in the \"Janitor NY Estimate\" field.");
theForm.pr_ny_estimate.focus();
return (false);
}
 
Code:
if (theForm.pr_ny_estimate.value.length < 1)
  {
    alert("Please enter at least 1 characters in the \"Janitor NY Estimate\" field.");
    [!]theForm.pr_ny_estimate.style.backgroundColor = "#ffff00";[/!]
    theForm.pr_ny_estimate.focus();
    return (false);
  }

-jeff
try { succeed(); } catch(E) { tryAgain(); } finally { rtfm(); }
i like your sleeves...they're real big
 
Now if I wanted to keep that value through a series of checks and then send them all at once would that be necessary or just leave it like that? For example rather than cal the alert after each one i would compile the fields that needs attention then call the alert. So
Code:
if (theForm.pr_ny_estimate.value.length < 1)
  {
    themessage = themessage + " -  Payroll Next year estimate";
    theForm.pr_ny_estimate.style.backgroundColor = "#ffff00";
    theForm.pr_ny_estimate.focus();
    return (false);
  }
//alert if fields are empty and cancel form submit
if (themessage == "You are required to complete the following fields: ") {
document.form.submit();
}
else {
alert(themessage);
return false;
   }
}
 
My apologies. the return fasle was in the wrong spot:

Code:
if (theForm.pr_ny_estimate.value.length < 1)
  {
    themessage = themessage + " -  Payroll Next year estimate";
    theForm.pr_ny_estimate.style.backgroundColor = "#ffff00";
  }
//alert if fields are empty and cancel form submit
if (themessage == "You are required to complete the following fields: ") {
document.form.submit();
}
else {
alert(themessage);
return false;
   }
}
 
Just to make coding a little easier, you can use the shorter syntax:
Code:
    themessage [!]+=[/!] " -  Payroll Next year estimate";

Tracy Dryden

Meddle not in the affairs of dragons,
For you are crunchy, and good with mustard. [dragon]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top