|
I have a drop-down menu:
<select name="clas" tabindex="6" STYLE="color: black; font: 8pt Verdana, Arial, Helvetica, sans-serif;">
<option value="1">First</option>
<option value="2">Business</option>
<option value="3">Economy</option>
<option value="4">Premium Economy</option>
</select>
I have a asp variable with a value of either 1,2,3 or 4.
How to i set the SELECTED value as the one that matches the ASP variable value.
e.g.
theclass = request("class")
response.Write "the class = "&theclass&"<br>"
gives me 3. How do i make <option value="3">Economy</option> the selected value?
Picco
|
|
|
<option value="3" selected>Economy</option>
<%
...
if(selected check) Response.Write(" selected")
....
|
|
|
|
|
In Notepad, create an HTML document with the HTML and head tags. Put this script in the head:
<script type="text/javascript">
function changeTheBox() {
var changeNum = parseInt(changer.value);
setTheBox(changeNum);
changeNum = changeNum + 1;
if (changeNum > 3)
{
document.all("changer").value = "0";
}
else
{
document.all("changer").value = changeNum;
}
}
function setTheBox(val) {
document.all("clas").selectedIndex = val;
}
</script>
Then, put this in between the body tags:
<select name="clas" tabindex="6" STYLE="color: black; font: 8pt Verdana, Arial, Helvetica, sans-serif;">
<option value="0">First</option>
<option value="1">Business</option>
<option value="2">Economy</option>
<option value="3">Premium Economy</option>
</select>
<input type="button" value="Change the Value" onclick="changeTheBox();" />
<input type="text" value="0" id="changer" name="changer" />
|
|
|
If you're trying to do it onload, you don't need to use jQuery, though you could do an document.onReady event function if you really wanted to use jQuery. But really, just take the function I provided above and just do an onload event with it, and pass it whatever parameter you need the dropdown to display. You can either hard-code it, or send it in the form of a URL parameter value that is obtained by another function you would call onload.
function setTheBox(val) {
document.all("clas").selectedIndex = val;
}
and "val" is the number of the value in the dropdown you want displayed. Just call it like this, or pass in the function name that gets the URL parameter:
<body onload="setTheBox(2)">
-Tom
|
|
|
If you're trying to do it onload, you don't need to use jQuery, though you could do an document.onReady event function if you really wanted to use jQuery. But really, just take the function I provided above and just do an onload event with it, and pass it whatever parameter you need the dropdown to display. You can either hard-code it, or send it in the form of a URL parameter value that is obtained by another function you would call onload.
function setTheBox(val) {
document.all("clas").selectedIndex = val;
}
and "val" is the number of the value in the dropdown you want displayed. Just call it like this, or pass in the function name that gets the URL parameter:
<body onload="setTheBox(2)">
-Tom
|
|
|
|
|
|
|
|