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 6 of 6
  1. #1
    New to the CF scene
    Join Date
    Aug 2003
    Location
    Va
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    works in firefox but not ie

    Can someone tell me why the following works in firefox but not in ie:

    <script>
    function ValidateForm(form){
    var curdate = new Date();
    var month = curdate.getMonth();

    if(form.numbers.value<=month && form.years.value==2005){
    alert('The expiration date you entered has expired. \n \nPlease enter a valid date.');
    return false;
    }
    return true;
    }

    </script>

    <body>
    <form action="hotels.htm" method="get" onsubmit="javascript:return ValidateForm(this)">
    <select name="numbers">
    <option></option>
    <option>01</option>
    <option>02</option>
    <option>03</option>
    <option>04</option>
    <option>05</option>
    <option>06</option>
    <option>07</option>
    <option>08</option>
    <option>09</option>
    </select>
    <select name="years">
    <option></option>
    <option>2005</option>
    <option>2006</option>
    <option>2007</option>
    </select>
    <input type="submit" name="Submit" value="Submit">
    </form>

  • #2
    Regular Coder martin_narg's Avatar
    Join Date
    Jul 2002
    Location
    Chamonix, France
    Posts
    600
    Thanks
    1
    Thanked 3 Times in 3 Posts
    will post a solution in a sec
    Last edited by martin_narg; 07-05-2005 at 04:00 PM.
    "Cos it's strange isn't it. You stand in the middle of a library and go 'Aaaaaaaaaaaaaaaaggggggghhhhhhh!'
    and everybody just stares at you. But you do the same in an aeroplane, and everybody joins in."
    -Tommy Cooper

  • #3
    New to the CF scene
    Join Date
    Aug 2003
    Location
    Va
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Now broke in firefox

    Still not working.
    Last edited by ryland22; 07-05-2005 at 03:58 PM.

  • #4
    Regular Coder martin_narg's Avatar
    Join Date
    Jul 2002
    Location
    Chamonix, France
    Posts
    600
    Thanks
    1
    Thanked 3 Times in 3 Posts
    You forgot to put the value attribute into the option tag mate.

    Code:
    <script>
    function ValidateForm(f){
    var curdate = new Date();
    var month = curdate.getMonth();
    	if(isNaN(parseInt(f.numbers.value))) {
    		alert('Please select month');
    		return false;
    	}
    	if( f.years.value.length < 1) {
    		alert('Please select year');
    		return false;
    	}
    	
    	if(parseInt(f.numbers.value) <= month && parseInt(f.years.value) == 2005) {
    		alert('The expiration date you entered has expired. \n \nPlease enter a valid date.');
    		return false;
    	}
    return true;
    }
    
    </script>
    <form name="frm" action="hotels.htm" method="get" onsubmit="return ValidateForm(this)">
    <select name="numbers">
    <option></option>
    <option value="1">01</option>
    <option value="2">02</option>
    <option value="3">03</option>
    <option value="4">04</option>
    <option value="5">05</option>
    <option value="6">06</option>
    <option value="7">07</option>
    <option value="8">08</option>
    <option value="9">09</option>
    </select>
    <select name="years">
    <option></option>
    <option value="2005">2005</option>
    <option value="2005">2006</option>
    <option value="2005">2007</option>
    </select>
    <input type="submit" name="Submit" value="Submit">
    </form>
    Hope this helps

    m_n
    "Cos it's strange isn't it. You stand in the middle of a library and go 'Aaaaaaaaaaaaaaaaggggggghhhhhhh!'
    and everybody just stares at you. But you do the same in an aeroplane, and everybody joins in."
    -Tommy Cooper

  • #5
    New Coder
    Join Date
    Jun 2005
    Posts
    82
    Thanks
    0
    Thanked 0 Times in 0 Posts
    EDIT: Ahh, sorry martin, didnt see your post when I started to debug.


    You didnt include "values" for your options, so when IE called the select box element on your form, there was no value set for each option, only a read only string denoting the text that appears representing each option. Here is the code that works in both IE and Firefox:
    Code:
    <script>
    function ValidateForm(form){
    var curdate = new Date();
    var month = curdate.getMonth();
    
    if (form.numbers.value <= month && form.years.value == 2005){
    alert('The expiration date you entered has expired. \n \nPlease enter a valid date.');
    return false; }
    else {
      return true;}
    }
    </script>
    
    <body>
    <form action="hotels.htm" method="get" onsubmit=" return ValidateForm(this)">
    <select name="numbers">
    <option></option>
    <option value="01">01</option>
    <option value="02">02</option>
    <option value="03">03</option>
    <option value="04">04</option>
    <option value="05">05</option>
    <option value="06">06</option>
    <option value="07">07</option>
    <option value="08">08</option>
    <option value="09">09</option>
    </select>
    <select name="years">
    <option></option>
    <option value="2005">2005</option>
    <option value="2006">2006</option>
    <option value="2007">2007</option>
    </select>
    <input type="submit" name="Submit" value="Submit">
    </form>
    
    </body>

  • #6
    New to the CF scene
    Join Date
    Aug 2003
    Location
    Va
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Right on!

    Thanks for the help - I didn't know ie required the values!


  •  

    Posting Permissions

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