Form Validation

Discussion in 'JavaScript' started by vassili, Feb 15, 2008.

  1. #1
    Hi, i have a form with multiple inputs, i need to validate before submitting that the sum of all inputs has to be greater than 0.

    my form will look something like this.

     <form name="form" etc...>
    
    <input type='text' name='qty1$uniq_ID'  value='0' size='1' maxlength='3' />
    <input type='text' name='qty2$uniq_ID'  value='0' size='1' maxlength='3' />
    
    </form>
    Code (markup):
    how should i proceed?
     
    vassili, Feb 15, 2008 IP
  2. KatieK

    KatieK Active Member

    Messages:
    116
    Likes Received:
    12
    Best Answers:
    0
    Trophy Points:
    58
    #2
    I prefer to use the ID on input elements to identify them. Assuming that, do something like this:

    field1 = document.getElementById("qty1");
    field2 = document.getElementById("qty2");
    if ( field1.value + field2.value > 0 )
    { form.submit(); }
     
    KatieK, Feb 18, 2008 IP