Please help me!

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Mike Brown

    Please help me!

    Please look at this section of my code. I am tryong to call the checkMonth
    function if the year selected is the current year. I tested the value being
    passed to the checkYear function and that is working. I seem to hava a
    problem with the syntax when I call the checkMonth() from the checkYear
    function? The rest of the site is coming along nicely. I am new but I am
    working hard to learn. Please help. Any advice would be appreciated.
    Thanks, Mike




    <html>



    <script language = "javascript ">

    function checkMonth()
    {
    var today = new Date();
    var thisMonth = today.getMonth( );
    var myValue = this.selectMont h.selectedIndex ;


    if (myValue <= thisMonth)
    {
    alert("Month has expired")
    }

    }

    function checkYear(myYea r)
    {
    var today = new Date();
    var thisYear = today.getFullYe ar();


    if (myYear == thisYear)
    {
    checkMonth();
    }

    }
    </script>





    <body>
    <hr>

    <form name= "myform" align = center>

    <table border = 0 align = "center">
    <tr>
    <td colspan = 2 align = center>Please select Payment Type</td>
    </tr>
    <br>
    <tr>
    <td><input type = "radio" name = "card" value = "visa">Visa
    <input type = "radio" name = "card" value = "MC">MC
    <input type = "radio" name = "card" value = "AmEx">AmEx
    <input type = "radio" name = "card" value = "Disc">Disc over
    </td>
    </tr>
    </table>

    <br>


    <table align = center>
    <tr>
    <td>Card Number</td>
    </tr>

    <tr>
    <td><input type = "text" name = "cardNumber " size = "16"></td>
    </tr>




    <tr>
    <td><br></td>
    </tr>

    <tr>
    <td>Expiratio n Date:</td>
    </tr>

    <tr>
    <td>Month</td>
    <td>Year</td>
    </tr>



    <tr>
    <td><select name = "selectMont h" >
    <option>Jan
    <option>Feb
    <option>Mar
    <option>Apr
    <option>May
    <option>Jun
    <option>Jul
    <option>Aug
    <option>Sep
    <option>Oct
    <option>Nov
    <option>Dec
    </select>
    </td>

    <td>
    <select name = "selectYear " onChange =
    "checkYear(this .options[selectedIndex].value);">

    <script language = "javascript ">

    var today = new Date();
    var thisYear = today.getFullYe ar();
    var endYear = thisYear + 8;

    for (i = endYear; i >= thisYear; i--)
    {
    document.write( "<option value=" + i + ">" + i);
    }

    </script>

    </select>
    </td>

    <tr>
    <td><br></td>
    </tr>

    <tr>
    <td>Reset Form</td>
    <td>Submit Order</td>
    </tr>

    <tr>
    <td><input type = "reset" value = "Clear"></td>
    <td><input type = "submit" value = "Send"></td>

    </tr>


    </form>
    </body>

    </html>


  • Fred Serry

    #2
    Re: Please help me!


    "Mike Brown" <mikeb455@cox.n et> schreef in bericht
    news:EqFYa.3104 0$ff.7131@fed1r ead01...[color=blue]
    > Please look at this section of my code. I am tryong to call the[/color]
    checkMonth[color=blue]
    > function if the year selected is the current year. I tested the value[/color]
    being[color=blue]
    > passed to the checkYear function and that is working. I seem to hava a
    > problem with the syntax when I call the checkMonth() from the[/color]
    checkYear[color=blue]
    > function? The rest of the site is coming along nicely. I am new but I[/color]
    am[color=blue]
    > working hard to learn. Please help. Any advice would be appreciated.
    > Thanks, Mike
    >
    >
    >
    >
    > <html>
    >
    >
    >
    > <script language = "javascript ">
    >
    > function checkMonth()
    > {
    > var today = new Date();
    > var thisMonth = today.getMonth( );
    > var myValue = this.selectMont h.selectedIndex ;
    >
    >
    > if (myValue <= thisMonth)
    > {
    > alert("Month has expired")
    > }
    >
    > }
    >[/color]
    <snip code>

    Hi,

    "this" does not have the scope that you obviously expect from it here.
    Try:

    var myValue = document.forms["myform"].selectMonth.se lectedIndex;

    Fred


    Comment

    • Vjekoslav Begovic

      #3
      Re: Please help me!


      "Mike Brown" <mikeb455@cox.n et> wrote in message
      news:EqFYa.3104 0$ff.7131@fed1r ead01...[color=blue]
      > Please look at this section of my code. I am tryong to call the checkMonth
      > function if the year selected is the current year. I tested the value[/color]
      being[color=blue]
      > passed to the checkYear function and that is working. I seem to hava a
      > problem with the syntax when I call the checkMonth() from the checkYear
      > function? The rest of the site is coming along nicely. I am new but I am
      > working hard to learn. Please help. Any advice would be appreciated.
      > Thanks, Mike[/color]
      [color=blue]
      > <html>
      > <script language = "javascript ">
      > function checkMonth()
      > {
      > var today = new Date();
      > var thisMonth = today.getMonth( );
      > var myValue = this.selectMont h.selectedIndex ;
      >
      >
      > if (myValue <= thisMonth)
      > {
      > alert("Month has expired")
      > }
      >
      > }
      >
      > function checkYear(myYea r)
      > {
      > var today = new Date();
      > var thisYear = today.getFullYe ar();
      >
      >
      > if (myYear == thisYear)
      > {
      > checkMonth();
      > }
      >
      > }
      > </script>
      >
      >
      >
      >
      >
      > <body>
      > <hr>
      >
      > <form name= "myform" align = center>
      >
      > <table border = 0 align = "center">
      > <tr>
      > <td colspan = 2 align = center>Please select Payment Type</td>
      > </tr>
      > <br>
      > <tr>
      > <td><input type = "radio" name = "card" value = "visa">Visa
      > <input type = "radio" name = "card" value = "MC">MC
      > <input type = "radio" name = "card" value = "AmEx">AmEx
      > <input type = "radio" name = "card" value = "Disc">Disc over
      > </td>
      > </tr>
      > </table>
      >
      > <br>
      >
      >
      > <table align = center>
      > <tr>
      > <td>Card Number</td>
      > </tr>
      >
      > <tr>
      > <td><input type = "text" name = "cardNumber " size = "16"></td>
      > </tr>
      >
      >
      >
      >
      > <tr>
      > <td><br></td>
      > </tr>
      >
      > <tr>
      > <td>Expiratio n Date:</td>
      > </tr>
      >
      > <tr>
      > <td>Month</td>
      > <td>Year</td>
      > </tr>
      >
      >
      >
      > <tr>
      > <td><select name = "selectMont h" >
      > <option>Jan
      > <option>Feb
      > <option>Mar
      > <option>Apr
      > <option>May
      > <option>Jun
      > <option>Jul
      > <option>Aug
      > <option>Sep
      > <option>Oct
      > <option>Nov
      > <option>Dec
      > </select>
      > </td>
      >
      > <td>
      > <select name = "selectYear " onChange =
      > "checkYear(this .options[selectedIndex].value);">
      >
      > <script language = "javascript ">
      >
      > var today = new Date();
      > var thisYear = today.getFullYe ar();
      > var endYear = thisYear + 8;
      >
      > for (i = endYear; i >= thisYear; i--)
      > {
      > document.write( "<option value=" + i + ">" + i);
      > }
      >
      > </script>
      >
      > </select>
      > </td>
      >
      > <tr>
      > <td><br></td>
      > </tr>
      >
      > <tr>
      > <td>Reset Form</td>
      > <td>Submit Order</td>
      > </tr>
      >
      > <tr>
      > <td><input type = "reset" value = "Clear"></td>
      > <td><input type = "submit" value = "Send"></td>
      >
      > </tr>
      >
      >
      > </form>
      > </body>
      >
      > </html>[/color]

      Instead of
      var myValue = this.selectMont h.selectedIndex ;



      put
      var myValue=documen t.forms['myform'].selectMonth.se lectedIndex




      Comment

      Working...