How to check for empty values on two fields then prompt user of error using javascript

Posted by Matthew on Stack Overflow See other posts from Stack Overflow or by Matthew
Published on 2010-03-16T20:55:24Z Indexed on 2010/03/16 21:41 UTC
Read the original article Hit count: 321

Hello guys,

I hope I can explain this right I have two input fields that require a price to be entered into them in order for donation to go through and submit.

The problem that I am having is that I would like the validation process check to see if one of the two fields has a value if so then proceed to submit. If both fields are empty then alert.

This is what I have in place now:

 function validate_required(field,alerttxt)
 {
 with (field)
 {
    if (value==null||value=="")
    {alert(alerttxt);return false;}
 else {return true}
 }
 }

function validate_form(thisform)
{
with (thisform)
{
    if (validate_required(input1,"Need a donation amount to continue")==false)
    {input1.focus();return false;}

    else if (validate_required(input2,"Need a donation amount to continue")==false)
    {input2.focus();return false;}
}
}

I would like to ultimately like to get this over to Jquery as well

Thanks guys any help would do

Matt

© Stack Overflow or respective owner

Related posts about JavaScript

Related posts about form-validation