View Full Version : pulling face value from list options
JackFruit3D
08-05-2002, 02:44 AM
Mind my ingorance...
I have a drop down list which is similar to as follows:
<Input......>
<option Value="001">Red</Option>
<option Value="002">Blue</Option>
<option Value="003">Green</Option>
<option Value="004">Purple</Option>
....
on posting the form, i only want to grab the face (name of the color) value... not the actual value to the selected option, then using what ever call i should use... GetParam("???") or what ever
thanx
whammy
08-05-2002, 03:40 AM
Then use the value as the color name:
<option value="red">red</option>
:)
Either that, or use some logic to change 001 to red later on, etc.:
If Request.Form("mycolor") = "001" Then mycolor = "red"
That's not the most elegant way to do it, but it works. You could also make arrays, etc...
the best way to handle this of course depends on how you create the drop down, and what you want to do with the value.
whammy's sollution is fine for a non-databasedriven app, buth it might be more efficient to generate the dropdown, based on the colors in your DB. (remember thet html was ment to be generated automatically !)
after the form was posted, you could translate the value back into the colours name.
it takes a little bit longer, buth its it doesn't give you any 'updating problems'.
example code to generate drop down list (some of it is in dutch, buth that shouln't be a problem, I think)
<form action="ven_eigenschappen_soort.asp" target="body" id="FORM1" method="post" name="FORM1">
<b>Klik op de gewenste soort.</b>
<p><select id="select1" name="soorten" size="10" onclick="submit();">
<%
dim conGranIT
set conGranIT=server.CreateObjec ("adodb.connection
conGranIT.Open("provider=microsoft.jet.oledb.4.0;data source="&server.MapPath("granit.mdb"))
dim rsSoort 'variabele voor recordset declareren
set rsSoort = server.CreateObject("adodb.recordset") dim
sql="select nummer,naam from soorten where categorie=eencategorie"
sql=replace(sql,"eencategorie",request.form("categorie"))
rsSoort.Open sql, conGranIT
do while rsSoort.EOF=false
Response.Write("<option value=" & rsSoort.Fields("nummer")& ">")
Response.Write(server.HTMLEncode(rsSoort.Fields("naam")) & "</option>")
rsSoort.MoveNext
loop
rsSoort.Close
conGranIT.Close
set rsSoort=nothing
set conGranIT = nothing
%>
RadarBob
08-06-2002, 04:40 PM
IMHO you should do this on the client side before passing the value. In general, if the client side is where you are selecting/building/prompting for/etc. values then that's where you should tweak things so that the exact value you want is passed - NOT tweaking the value after you pass it. Don't force your server-side to have to "know" things it shouldn't have to.
Besides all that above; the DOM gives you some very handy properties with which to manipulate the <select> object - and you loose all that in the request.form collection.
Here's how it might be done - in Javascript on the client:
NOTE:
form = the name of your HTML form
color = the name of your select object
for (var i=0; i<form.color.length; i++) {
if (form.color.options[i].selected)
form.color.options[i].value = form.color.options[i].text;
}
There!:thumbsup: You might put this in a function called by an "onchange" event in your <select> object.
RadarBob
08-06-2002, 08:06 PM
I just ran into this in HTML 4 Unleashed
The OPTION element can also have a specified value assigned to it, but that's not required. If it's absent, the contents of the OPTION element will become the “value” part of the name/value pair
In other words leave off the "value='004'" part and the text part becomes the value passed in the form submission.
whammy
08-07-2002, 04:45 AM
Pretty much the same thing I said, just make the values the same as the text and validate them later.
JackFruit3D
08-07-2002, 04:52 AM
In the end i used the following...
Client side manipulation... so prolly wasn't the best posting it in the Server side forums... but thanx anyway
<form>
<select name="tst">
<option Value="001">Red</Option>
<option Value="002">Blue</Option>
<option Value="003">Green</Option>
<option Value="004">Purple</Option>
</select>
<input type="button" value="test" onClick="alert(this.form.tst[this.form.tst.selectedIndex].text);">
</form>
vBulletin® v3.8.2, Copyright ©2000-2012, Jelsoft Enterprises Ltd.