Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New to the CF scene
    Join Date
    Feb 2004
    Location
    UK
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Problem with Combobox Validation

    >> Sorry this really should have been a reply to my previous message "Validation Script won't work in Mozilla! Why?"

    Hi guys thanks for the help with the previous problem... the first 2 validation methods now work in Mozilla fine! However I am still having trouble with the last one, which checks the values of the Start and End Dates. The code for the combo box is this:

    Code:
    <br></tr><tr><td>Start Week: </td><td><select name="startweek" size=1><br>
              <option selected value=1>1
              <option value=2>2
              <option value=3>3
              <option value=4>4
              <option value=5>5
              <option value=6>6
              <option value=7>7
              <option value=8>8
              <option value=9>9
              <option value=10>10
              <option value=11>11
              <option value=12>12
              <option value=13>13
              <option value=14>14
              <option value=15>15</select>
    
    <br></tr><tr><td>End Week: </td><td><select name="endweek" size=1><br>
              <option value=1>1
              <option value=2>2
              <option value=3>3
              <option value=4>4
              <option value=5>5
              <option value=6>6
              <option value=7>7
              <option value=8>8
              <option value=9>9
              <option value=10>10
              <option value=11>11
              <option value=12>12
              <option value=13>13
              <option value=14>14
              <option selected value=15>15</select>
              <br></tr><tr><td>Day of Week: </td><td><select name="day" size=1><br>
    And the Javascript now looks like this:

    Code:
    function validate(objForm) {
    return checkProgramme(objForm) && checkCapacity(objForm) && checkWeeks(objForm);
    }
    
    function checkProgramme(objForm) {
        if (objForm.programme.value != "select") { 
    	return true;
        }
        else {
            alert('You must select a programme.');
            return false;
        }
    }
    
    function checkCapacity(objForm) {
        if ((objForm.capacity.value >0) && (objForm.capacity.value <501)) { 
    	return true;
        }
        else {
            alert('Capacity must be between 1 and 500.');
            return false;
        }
    }
    
    function checkWeeks(objForm) {
        if (objForm.startweek.value <= objForm.endweek.value) { 
    	return true;
        }
        else {
            alert('The end week must be later than the start week.');
            return false;
        }
    }
    Startweek must always be less then or equal to endweek...
    The validation works fine, until I select a value in Starweek that is greater than 1 and a value in Endweek that is greater than 10.

    For example - 1 Start and 15 End validates fine (No Error), as does 6 Start and 3 End (Error Message is Shown)...

    2 Start and 11 End will generate the Error Message even though it should not....

    What am I missing here?

    Thanks very much!
    Last edited by Daedalus; 02-12-2004 at 06:41 PM.

  • #2
    Regular Coder
    Join Date
    Jul 2002
    Posts
    698
    Thanks
    0
    Thanked 0 Times in 0 Posts
    perhaps this if works better-

    if (parseInt(objForm.startweek.value,10) <= parseInt(objForm.endweek.value,10))

  • #3
    New to the CF scene
    Join Date
    Feb 2004
    Location
    UK
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts
    That seems to be working perfectly! Thank you very much.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •