Populate Drop Down

This is a discussion on "Populate Drop Down" within the Classic ASP section. This forum, and the thread "Populate Drop Down are both part of the Program Your Website category.


 Subscribe in a reader

Go Back   Webforumz.com > Main Forums > Program Your Website > Classic ASP

Notices




Reply
 
LinkBack Thread Tools
  #1  
Old Jan 18th, 2006, 04:58
Junior Member
Join Date: Dec 2005
Posts: 24
Thanks: 0
Thanked 0 Times in 0 Posts
Populate Drop Down

I'm trying to populate a dropdown list with a default selected current year. I was using:
Code: Select all
<%
yearnow = Right(Year(Date),4)
%>
<select name="Season_Year">
<%
i = "1986"
FOR LoopCtr = 1 to 50
Response.Write "<option value=" & chr(34) & i & chr(34)
IF yearnow = i THEN
Response.Write " selected=" &chr(34) & "selected" & chr(34)
END IF
Response.Write ">" & i & "</option>" &VbCrLf
i = i + 1
NEXT
%>
But this code will not create the selected text in the IF statement. I am assuming that is because yearnow is a date so that the value will be different than when i = 2006. So, I came up with
Code: Select all
yearnow = dateadd("yyyy",0,date())
%>
<select name="Season_Year">
<%
n = -20
i = dateadd("yyyy",n,date())
FOR LoopCtr = 1 to 100
Response.Write "<option value=" & chr(34) & Right(i,4) & chr(34)
IF yearnow = i THEN
Response.Write " selected=" &chr(34) & "selected" & chr(34)
END IF
Response.Write ">" & Right(i,4) & "</option>" &VbCrLf
n = n + 1
i = dateadd("yyyy",+n,date())
NEXT
This seems to work, but I would rather stay away from the date format for the values, if that is what is happening. Does anyone know of a better way of doing this?
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote

  #2  
Old Jan 18th, 2006, 16:22
Reputable Member
Join Date: Sep 2003
Location: USA
Posts: 112
Thanks: 0
Thanked 0 Times in 0 Posts
Re: Populate Drop Down

I'm not sure why you used
Code: Select all
yearnow = Right(Year(Date),4)
Right is a string function and will convert your value to a string thus you are doing
2004="2004" which is false

I would just use
Code: Select all
 yearnow = Year(Date)
Does this somehow create problems for you?
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #3  
Old Jan 18th, 2006, 19:42
Junior Member
Join Date: Dec 2005
Posts: 24
Thanks: 0
Thanked 0 Times in 0 Posts
Re: Populate Drop Down

Right, thanks. I wasn't thinking that using Right would make it a string. Silly me.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #4  
Old Jan 18th, 2006, 21:12
Junior Member
Join Date: Dec 2005
Posts: 24
Thanks: 0
Thanked 0 Times in 0 Posts
Re: Populate Drop Down

That code seems to be working well for me, thanks again. I do have another problem though. I am sending the form to the same page for the action. If there is a problem, like they forgot to enter required information, then the form will be populated with the information that they entered with a note about what to change. I want the drop down to keep the information that they entered. I tried
Code: Select all
<form action="Testfor.asp" method="post">
<select name="frmDay">
<%
a = Request.Form("frmDay")
i = 1
FOR LoopCtr = 1 to 31
Response.Write "<option value=" & chr(34) & i & chr(34)
IF a = i  THEN
Response.Write "selected=" &chr(34) & "selected" & chr(34)
END IF
Response.Write ">" & i & "</option>" &VbCrLf
 
i = i + 1
NEXT
%>
 
<input type="submit" name="Submit" value="Submit">
</form>
I can't seem to get i to equal a so that the "selected='selected'" part shows up. I have tried a couple of different ways, but no matter what I tried, I couldn't get it to work. Any ideas?
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #5  
Old Jan 18th, 2006, 21:22
Reputable Member
Join Date: Sep 2003
Location: USA
Posts: 112
Thanks: 0
Thanked 0 Times in 0 Posts
Re: Populate Drop Down

it's the same kind of problem. Everything from the request scope is a string so try
Code: Select all
if isnumeric(request.form("frmDay")) then a=cint(request.form("frmDay"))
it's good practice to test the isnumeric even though it's coming from you..
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #6  
Old Jan 18th, 2006, 21:31
Junior Member
Join Date: Dec 2005
Posts: 24
Thanks: 0
Thanked 0 Times in 0 Posts
Re: Populate Drop Down

Thanks again. I thought that maybe the variable was being changed to a different type, but I couldn't find anything about that or how to change it.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
Reply

Tags
populate, drop, down

Thread Tools

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
Drop down menus drop behind flash header theGAME71135 Flash & Multimedia Forum 3 Jan 10th, 2008 09:42
Dependant Drop-down Help phoenix211984 JavaScript Forum 1 Oct 13th, 2006 17:44
Looking for Script to sort table data (& populate database) toasty PHP Forum 1 Oct 13th, 2006 17:42
drop shadow?? karloff Graphics and 3D 7 Aug 4th, 2006 14:08
How should I populate the following table. macupryk Databases 1 Oct 15th, 2003 23:34


All times are GMT. The time now is 04:08.


Powered by vBulletin®
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.2.0 RC8
© 2003-2008 Webforumz.com : All Rights Reserved

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42