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!

Validating form field existence then value

Status
Not open for further replies.

bamboo

Programmer
Aug 22, 2001
89
US
I'm trying to figure out how to first validate that a form field exists, if so, then to validate whether it is empty. If the field doesn't exist then move onto to the next field. I have an 8 field form and I only need to do this double validation on 2 of the fields. This is a CF application where depending on what type of request it is, the particular field will display (either Cash or Stock text field). So here are the two fields that I need to validate. This of course is the bare bones script I'm starting out with assumming both field are present.

function Validate()
{

//validate stock field
if (document.capsia_form.stock.value="")
{
alert("Please enter a stock amount");
return false;
}

//validate cash field
if (document.capsia_form.cash.value="")
{
alert("Please enter a cash amount");
return false;
}

return true;
}

 
to see if a form input box exists, use the if statement like so-
if(document.capsia_form.cash) {
alert("cash amount input box does exist")
}
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top