Click to See Complete Forum and Search --> : date selection in ASP
preetilak
08-07-2005, 10:00 PM
I am developing a site on ASP which does not support JavaScript. Is there a way to have dropdown date in the following format....
<select....for day> <select for Month> <select for year>
in ASP. The select values must be in numbers.
buntine
08-07-2005, 10:45 PM
Yes. Its not ASP or JavaScript, though. It is HTML. ;)
You have to do is generate the combo boxes with a simple loop. I would recommend you write a little sub-routine to handle this.
Public Sub GenerateNNumericSelectBox(strName, intStart, intEnd)
Dim i
If Not IsNumeric(intStart) Or Not IsNumeric(intEnd) Then
Exit Sub
End If
With Response
.Write "<select name=""" & strName & """>" & VbCrLf
For i = intStart To intEnd
.Write "<option value=""" & i & """>" & i & "</option>" & VbCrLf
Next
.Write "</select>" & VbCrLf
End With
End Sub
Response.Write GenerateNumericSelectBox("cboDay", 1, 31)
Response.Write GenerateNumericSelectBox("cboMonth", 1, 12)
Response.Write GenerateNumericSelectBox("cboYear", 2000, 2030)
Regards.
preetilak
08-07-2005, 11:41 PM
thanks,
But I encounter the following error....
Microsoft VBScript runtime error '800a000d'
Type mismatch: 'GenerateNumericSelectBox'
/i_mode/date.asp, line 22
buntine
08-08-2005, 12:18 AM
Ok. Silly mistake on my behalf.
Try this:
GenerateNumericSelectBox("cboDay", 1, 31)
GenerateNumericSelectBox("cboMonth", 1, 12)
GenerateNumericSelectBox("cboYear", 2000, 2030)
Regards.
preetilak
08-08-2005, 12:58 AM
I see this error when I use the corrected code...
Microsoft VBScript compilation error '800a0414'
Cannot use parentheses when calling a Sub
/i_mode/date.asp, line 22
GenerateNumericSelectBox("cboDay", 1, 31)
-----------------------------------------^
buntine
08-08-2005, 01:30 AM
Alright. Another mistake. This is what happens when you just write code into the form. :p Just remove the parantheses.
GenerateNumericSelectBox "cboDay", 1, 31
GenerateNumericSelectBox "cboMonth", 1, 12
GenerateNumericSelectBox "cboYear", 2000, 2030
Regards.
preetilak
08-08-2005, 01:58 AM
Thanks.
buntine
08-08-2005, 02:05 AM
Some closure would be appreciated. Is this working for you? Would you like to know exactly how it works (for educational purposes)?
Regards.
preetilak
08-08-2005, 03:47 AM
yes sure. The code worked. I would like to know why it did not work with the '( )'. Normally, when we write a function, we pass the params like fnName(param1,....). Why not so with this?
buntine
08-08-2005, 04:43 AM
Because it was not a function, but a sub-routine. Functions return a value, sub-routines do not. ;)
Truthfully, I do not know the official reason. VBScript just does not like it when we use parentheses on sub-routines with more than one paramater.
Google should warrant the actual reason, though.
Regards.