Photo Gallery Member List Search Calendars FAQ Ticket List Log Out


Select box default

 
Logged in as: Guest
arrSession:exec spGetSession 2,3,30
 Active Users: There are 0 members and 0 guests.
 Users viewing this topic: none
 

 

 
  
  Printable Version
All Forums >> [Scripting] >> ASP >> Select box default
  Do you like VisualBasicScript.com? Link to us and help spread the word about our forum. Thanks!
Page: [1]
Login
Message << Older Topic   Newer Topic >>
 Select box default - 5/23/2001 6:17:22 AM   
  daydreamer

 

Posts: 19
Score: 0
Joined: 5/23/2001
From: USA
Status: offline
Hail,

Here's a quick one, on one of my asp pages, I load 4 select boxes with choices taken from a access database. How do you display one default choice per box without adding (or doubling) that item in the select box.

If you have following items A, B, C, D and E and want D to show when page loads. I put the <OPTION selected>D</OPTION> but obviously this is wrong because it doubles the D selection in the list. Is there a way maybe to specify the item number like in VB with a combobox?

Phailak
 
 
Post #: 1
 
 Re: Select box default - 5/23/2001 6:20:38 AM   
  adminkoe

 

Posts: 117
Score: 0
Joined: 12/23/2000
From:
Status: offline
How does that double the selection??? That's the way to do it, short of writing an inline javascript statement that would set it like you want it --

<script>
document.formName.selectName.value = wantedValue;
</script>

But if you have 5 options, and just put "selected" by one of them, that should not make two entries in the box -- just the one -- and it will be selected....

(in reply to daydreamer)
 
 
Post #: 2
 
 Re: Select box default - 5/23/2001 6:23:26 AM   
  daydreamer

 

Posts: 19
Score: 0
Joined: 5/23/2001
From: USA
Status: offline
Well, this is what I have, I must of screwed up somewhere...

<%@ Language=VBScript %>
<html>
<%
Dim UID
UID = request.querystring("Player")
%>
<form name=frmTT method=post action=SavingChr.asp?Player=<%=UID%>>
<head>
<title>Gladiators</title>
</head>

<body text="#000000" bgcolor="#C0C0C0" link="#0000EE" vlink="#FFFF99" alink="#FF0000">

<center><font size=+4>Creating your Gladiator</font><font size=+4></font>
<p><font size=+2>Now we must decide the strength of your character. Below, you have several choices that will define your gladiator. You must first choose a name, one that will reflect your glory in the Emperor's archives. (Let's not exagerate with the length, I say 25 characters should be enough!).</font>
<p><font size=+2>Then simply choose your desired race, each has their own advantage depending on size (Smaller creatures are faster, bigger ones are stronger while average height such as humans are balanced). Weapon represents your weapon of choice that you were raised to fight with. Style is how you fight and sponsor is whom you seek to represent at the tournaments.</font>
<p><font size=+2>Finally, you may reroll your stats as many times as you wish, just press the reroll button of the following page.</font>
<br><br><br>
<%
sql = "select race from races "
Set Conn = Server.CreateObject("ADODB.Connection")
Conn.Open "Glad"
Set rs = Server.CreateObject("ADODB.Recordset")
rs.Open sql, Conn
%>
<BR>
<BR>
<font size=+3>Choose your race</font>
<BR>
<select NAME="cmbRaces">
<%Do while not rs.eof%>
<OPTION value="<%= rs("race") %>"><%=rs("race")%>
<OPTION selected>Choose your race</option>
<%rs.movenext%>
<%loop%>
<%rs.close%>
</select>
<%
sql = "select name, bonus from skills "
rs.Open sql, Conn
%>
<BR>
<BR>
<font size=+3>Choose your inate skill</font>
<BR>
<select NAME="cmbSkills">
<%Do while not rs.eof%>
<OPTION value="<%= rs("name") %><%= rs("bonus") %>"><%=rs("name")%><---><%= rs("bonus") %>
<%rs.movenext%>
<%loop%>
<OPTION selected>Choose your inate skill</option>
<%rs.close%>
</select>
<%
sql = "select name, bonus from styles "
rs.Open sql, Conn
%>
<BR>
<BR>
<font size=+3>Choose your style of combat</font>
<BR>
<select NAME="cmbStyles">
<%Do while not rs.eof%>
<OPTION value="<%= rs("name") %><%= rs("bonus") %>"><%=rs("name")%><---><%= rs("bonus") %>
<%rs.movenext%>
<%loop%>
<OPTION selected>Choose your style of combat</option>
<%rs.close%>
</select>
<%
sql = "select name, bonus from sponsors "
rs.Open sql, Conn
%>
<BR>
<BR>
<font size=+3>Choose your sponsor</font>
<BR>
<select NAME="cmbSponsors">
<%Do while not rs.eof%>
<OPTION value="<%= rs("name") %><%= rs("bonus") %>"><%=rs("name")%><---><%= rs("bonus") %>
<%rs.movenext%>
<%loop%>
<OPTION selected>Choose your sponsor</option>
<%
rs.close
conn.close
set rs = nothing
set conn = nothing
%>
</select>
<br><br><br>
<div align=center><input type=submit value=Accept></div><br><br>
</body>
</form>
</html>

So this shows on the page what I want it to show and appears in the choices so I thought, I'll write these defaults in HTML and put the first one of each list as a default, but when I write it in, it's doubled in the list. This is what I mean:
Let's say "Human" is part of the races list, well in the line
<OPTION selected>Choose your race</option> I replaced "Choose your race" by "Human" and Human doubled up in the list???

While I have your attention, I'm at a point now where the user may go many different ways from a page. Let's say I have 5 different buttons which lead to 5 different pages, what would the buttons looks like, can I do...
First button is "Arena" so
<input type=button value=Arena OnClick=Arena.asp>
Now I know that is not the right syntax at all, but is it something just as simple?

(in reply to daydreamer)
 
 
Post #: 3
 
 Re: Select box default - 5/23/2001 6:25:10 AM   
  adminkoe

 

Posts: 117
Score: 0
Joined: 12/23/2000
From:
Status: offline
Without wading through that entire code posting -- here are a few general pointers --

If I have a value in a variable that I want to be selected in the list -- and I know that the value will appear in the recordset at some point, then I'll do this:

<select name=whatever>
<option value=none>SELECT ONE</option>
<%
while not rs.eof
response.write("<option value=" & rs("value"))
if rs("value") = valueImLookingFor then
response.write(" selected")
end if
response.write(">" & rs("value") & "</option>")
rs.movenext
wend
%>
</select>

So that the loop looks and compares the value on each iteration -- and when it finds it, it inserts the 'selected' keyword, and we're good to go --

As far as changing the target -- here's another simplified example that is enough to give you the idea of what is going to have to happen --

<input type=button value="Page One" onClick="makeJump('pageOne.asp');">
<input type=button value="Page Two" onClick="makeJump('pageTwo.asp');">

<script language=javascript>
function makeJump(page){
var url = page + anyOtherQueryStringStuffYouNeed
location = url;
}
</script>

So that you attach your querystring information on to the end of the url manually rather than having it automatically happen with a submit button, and the redirect using the javascript statement, 'location=url;' -- and you've effectively created your own 'get' type form submission --

(in reply to daydreamer)
 
 
Post #: 4
 
 
 
  

If you found our site useful please link to us <a href="http://www.visualbasicscript.com">VisualBasicScript.com</a>.
All Forums >> [Scripting] >> ASP >> Select box default Page: [1]
Jump to:





New Messages No New Messages
Hot Topic w/ New Messages Hot Topic w/o New Messages
Locked w/ New Messages Locked w/o New Messages
 Post New Thread
 Reply to Message
 Post New Poll
 Submit Vote
 Delete My Own Post
 Delete My Own Thread
 Rate Posts