Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

year in drop down box based on system date

Status
Not open for further replies.

pleashelp

Technical User
Feb 27, 2002
97
US
I have an information form that I am building within a table. I got everything working except that I need a drop down box that will give the system year plus 6 additional years based, of course, on the system date. I can't figure out how to make this happen.
 
this could easily be done with javascript, however I suggest you do this server-side, because anyone with javascript disabled will not be able to pick a month.

*cLFlaVA
----------------------------
[tt]I already made like infinity of those at scout camp...[/tt]
[URL unfurl="true"]http://www.coryarthus.com/[/url]
[banghead]
 
I really want to do this in javascript..not on the server side
 
sigh...

Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
	"[URL unfurl="true"]http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">[/URL]

<html>
<head>
<title>Untitled</title>

<script type="text/javascript"><!--
function fillYears(s) {
    var d = new Date();
    var y = d.getFullYear();
    for ( var i = 0; i < 7; i++ )
        s.options[i] = new Option(y+i,y+i);
}

onload=function() { fillYears(document.forms['f'].elements['selYear']); };
//--></script>

</head>

<body>

<form name="f">
    <select name="selYear"></select>
</form>

</body>
</html>

*cLFlaVA
----------------------------
[tt]I already made like infinity of those at scout camp...[/tt]
[URL unfurl="true"]http://www.coryarthus.com/[/url]
[banghead]
 
that's great!! When I run that code alone, it works fine. So I put the first part up in the head. Then I put the second part in my table detail and I get the drop down but no dates in it.

here is what I put in the head--
<HEAD><TITLE>FORM</TITLE>

<script type="text/javascript"><!--
function ccYear(card) {
var date = new Date();
var year = date.getFullYear();
for ( var x = 0; x < 7; x++ )
card.options[x] = new Option(year+x,year+x);
}

onload=function() { ccYear(document.forms['ExpYear'].elements['newYear']); };
//--></script>

</HEAD>

And here is what I put in the TD section--

<TD width ="12%" ><label name="YearList">Year


<form name="ExpYear">
<select name="newYear"></select>
</form>
</TR></TABLE>

VOILA!! Nothing in the drop down..Am I putting something in the wrong section?
 
post your actual code, not what you THINK is your actual code. your html, if that's real, is terribly formed. that could be the reason.

*cLFlaVA
----------------------------
[tt]I already made like infinity of those at scout camp...[/tt]
[URL unfurl="true"]http://www.coryarthus.com/[/url]
[banghead]
 
OK> Here is the code that I have so far. Since I am just starting out in this, I am basically taking it one step at a time. The credit card month shows a drop down box with the month numbers in it and now I am working on the year plus 6 additional years.

Here is the code:

<!DOCTYPE HTML PUBLIC "//W3C//DTD HTML 4.0 Transitional//EN">

<HTML><HEAD><TITLE>Information</TITLE>



<script type="text/javascript"><!--
function ccYear(card) {
var date = new Date();
var year = date.getFullYear();
for ( var x = 0; x < 7; x++ )
card.options[x] = new Option(year+x,year+x);
}

onload=function() { ccYear(document.forms['ExpYear'].elements['newYear']); };
//--></script>



</HEAD>
<BODY text=blue vLink=#ffe4c4 link=#ffcc33 bgColor=#fffff0>

<TABLE>
<TBODY>
<TR>
<TD width="25%" bgColor=navy><B><FONT color=#ffffff><FONT
face="Comic Sans MS"><FONT size=2>Credit Card Info
</FONT></FONT></FONT></B></TD></TR></TBODY></TABLE>
<TABLE width="50%" border=1>
<TBODY>
<TR>
<TD width="100%" bgColor=#ffffff><!-- Color code "#FFFFFF" is a bright blue--><INPUT
type=radio CHECKED name=info> <FONT face="Comic Sans MS"
size=2 color=blue><B> Visa </B></FONT></TD></TR>
<TR>
<TD bgColor=#ffffff><INPUT type=radio name=info> <FONT size=2
face="Comic Sans MS" color=blue><B>Mastercard</B></FONT> </TD></TR>
<TR>
<TD bgColor=#ffffff><!-- Color code "#FFFFFF" is a bright blue--><INPUT
type=radio name=info> <FONT face="Comic Sans MS" size=2
color=blue><B>American Express </B></FONT></TD></TR>
<TR>
<TD bgColor=#ffffff><!-- Color code "#FFFFFF" is a bright blue--><INPUT
type=radio name=info> <FONT face="Comic Sans MS" size=2
color=blue><B>Diners club </B></FONT></TD></TR>
<TR>
<TD bgColor=#ffffff><FONT face="Comic Sans MS" size=2><B>Credit Card #:
<INPUT type=password name=creditcard></B></FONT></TD></TR>



</TBODY></TABLE>


<!-- This table will give the Expiration date drop down boxes-->
<TABLE>
<TBODY>
</TBODY></TABLE>


<TABLE width="50%" border=1>

<TBODY>

<TR>


<TD width="7%" bgColor=#ffffff><FONT face="Comic Sans MS"
size=2><B><LABEL name="Exp. Date">Exp. Date <!This is the label for the row-->
</LABEL></TD>

<TD width ="12%" bgColor=#ffffff><FONT face="Comic Sans MS" size=2><B><label name="Month">Month
</LABEL></B></FONT> <!--This will give the month label-->


<B>
<FORM NAME = "MyForm"> <!-- This is the drop down box for the month -->
<SELECT name="Month" onchange="window.location=

document.MyForm.Month.options[document.MyForm.Month.selected Index].value">

<OPTION SELECTED VALUE="JAVASCRIPT:VOID(0)">-- PICK ONE --
<OPTION value=01>01
<OPTION value=02>02
<OPTION value=03>03
<OPTION value=04>04
<OPTION value=05>05
<OPTION value=06>06
<OPTION value=07>07
<OPTION value=08>08
<OPTION value=09>09
<OPTION value=10>10
<OPTION value=11>11
<OPTION value=12>12
</SELECT></B></FONT></TD>


<TD width ="12%" bgColor=#ffffff><FONT face="Comic Sans MS" size=2><B><label name="YearList">Year




<B>
<form name="ExpYear"> <!-- This is the drop down box for the year-->
<select name="newYear"></select>
</form>
</TR></TABLE>

 
The first problem I see is the embedded forms. You cannot place a form inside another form (plus your missing an end form tag on top of that).

barcode_1.gif
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top