Validating form field syntax issue

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • mistyqe
    New Member
    • Mar 2009
    • 2

    Validating form field syntax issue

    I have 2 fields I need to validate in a form.

    One is a drop-down box with a few options. The second is a text box where the user can enter their own value.

    The way it should work is that either the user can choose one option from the drop down box or enter his own value in the text box. But one of the two have to be filled.

    I am trying the following code, but it is stuck on the first validation. Keeps asking to choose from the drop-down even if something is already entered in the text box below. It should be an either / or thing, or an if.. then.. else.. thing, but I am not sure of the syntax. Please help.

    Code:
    if (x.budget_range.value == '1') 
    	{
    	alert("Please choose a budget range");
    	x.budget_range.focus();
    	return false;
            }
    
    if
           ((x.budget_range.value == '1') && (isBlank(x.budgetamt.value)))
    		{
    		alert("Please enter a budget");
    		x.budgetamt.focus();
    		return false;
    		}
    	}
    Last edited by Dormilich; Mar 28 '09, 09:36 AM. Reason: added [code] tags
  • acoder
    Recognized Expert MVP
    • Nov 2006
    • 16032

    #2
    If you remove the first if statement and just the second one, it should work OK. I presume 'x' refers to the form.

    Comment

    • mistyqe
      New Member
      • Mar 2009
      • 2

      #3
      I actually thought of the same solution minutes after I posted it here. :)) Guess that triggered the light bulb. Thank you though.

      Comment

      • acoder
        Recognized Expert MVP
        • Nov 2006
        • 16032

        #4
        No problem.

        PS. I see you're a new member. Welcome to Bytes! :)

        Comment

        Working...