Connecting Tech Pros Worldwide Help | Site Map

Please help me!

 
LinkBack Thread Tools Search this Thread
  #1  
Old July 20th, 2005, 09:33 AM
Mike Brown
Guest
 
Posts: n/a
Default 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.selectMonth.selectedIndex;


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

}

function checkYear(myYear)
{
var today = new Date();
var thisYear = today.getFullYear();


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">Discover
</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>Expiration Date:</td>
</tr>

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



<tr>
<td><select name = "selectMonth" >
<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.getFullYear();
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>



  #2  
Old July 20th, 2005, 09:34 AM
Fred Serry
Guest
 
Posts: n/a
Default Re: Please help me!


"Mike Brown" <mikeb455@cox.net> schreef in bericht
news:EqFYa.31040$ff.7131@fed1read01...[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.selectMonth.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.selectedIndex;

Fred


  #3  
Old July 20th, 2005, 09:34 AM
Vjekoslav Begovic
Guest
 
Posts: n/a
Default Re: Please help me!


"Mike Brown" <mikeb455@cox.net> wrote in message
news:EqFYa.31040$ff.7131@fed1read01...[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.selectMonth.selectedIndex;
>
>
> if (myValue <= thisMonth)
> {
> alert("Month has expired")
> }
>
> }
>
> function checkYear(myYear)
> {
> var today = new Date();
> var thisYear = today.getFullYear();
>
>
> 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">Discover
> </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>Expiration Date:</td>
> </tr>
>
> <tr>
> <td>Month</td>
> <td>Year</td>
> </tr>
>
>
>
> <tr>
> <td><select name = "selectMonth" >
> <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.getFullYear();
> 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.selectMonth.selectedIndex;



put
var myValue=document.forms['myform'].selectMonth.selectedIndex




 

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Popular Articles

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over 220,662 network members.