www.webdeveloper.com
Results 1 to 7 of 7

Thread: Help Please....

  1. #1
    Join Date
    Apr 2006
    Posts
    5

    Question Help Please....

    can you guys help me with my code... it's not running... can you figure-out what's wrong with my code or can suggest the correct code for this one... thank you very much!

    ==============================

    <html>
    <script type="text/javascript">

    function expdate()
    {
    var vmydate = document.form.mydate.value;
    Month = vmydate.substring(0,2);
    Year = vmydate.substring(2);

    if (Month>12)
    {
    alert("invalid month");
    //document.write("<b>invalid month</b><br>")
    }

    if (Year<05)
    {
    alert("invalid year");
    //document.write("<br><b>invalid year</b>")
    }
    }
    </script>

    <form>

    CC Expiration: <input type = "text" name= "myDate" value = ""> (MMYY)

    <input type = "button" name = "submit" value = "enter" onClick= "expdate()">

    </form>

    </html>

    =========================

  2. #2
    Join Date
    Jan 2006
    Location
    I'm in GMT -5
    Posts
    561
    Code:
    <html>
    <head>
    <script type="text/javascript">
    
    	function validate(nForm){
    
    		var expires = nForm['expDate'];
    		if (expires.value.length < 4 || expires.value.length > 4 || expires.value == "")
    			{
    			 alert('The expiration date is not 4 digits');
    			 expires.value = "";
    			 expires.focus();
    			 return false;
    			}
    		var nMonth = expires.value.substring(0,2)
    		var nYear = expires.value.substring(2,4);
    		if (Number(nMonth) < 1 || Number(nMonth) > 12)
    			{
    			 alert('Invalid expiration month');
    			 expires.value = "";
    			 expires.focus();
    			 return false;
    			}
    		if (Number(nYear) < 6)
    			{
    			 alert('Invalid expiration year');
    			 expires.value = "";
    			 expires.focus();
    			 return false;
    			}
    		return true;
    	}
    
    </script>
    </head>
    <body>
    
    <form method="post" action="" onsubmit="return validate(this)">
    Expiration Date MMYY: <input type='text' name='expDate' size='3'>
    <br>
    <input type='submit' value="Submit">
    </form>
    
    </body>
    </html>

  3. #3
    Join Date
    Apr 2006
    Posts
    5
    thank you very much... but i still have a problem with the code... for example the digits '1304' , the alert only says invalid month, it should be followed by another alert that says invalid year... how can we do that?

  4. #4
    Join Date
    Jan 2006
    Location
    I'm in GMT -5
    Posts
    561
    Sorry, but if one part is "invalid" the rest of the function is not executed.

  5. #5
    Join Date
    Apr 2006
    Location
    Houston
    Posts
    1,374
    Quote Originally Posted by cutesykayus
    ...it should be followed by another alert that says invalid year... how can we do that?
    Homework assignement ?

  6. #6
    Join Date
    Apr 2006
    Posts
    5
    Quote Originally Posted by James Gatka
    Sorry, but if one part is "invalid" the rest of the function is not executed.
    ah ok... yeah you're right! thank you very much sir! you're so nice to help me thanks!

  7. #7
    Join Date
    Apr 2006
    Posts
    5
    Quote Originally Posted by slaughters
    Homework assignement ?
    yup.. assignment... :-(

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles