codetoad.com
Home||ASP|ASP.Net|C++/C#|DHTML|HTML|Java|Javascript|Perl|VB|XML||CodeToadPlus!||Forums||RAM
Search Site:
Search Forums:
drop-down menu selected value crmpicco at 13:30 on Thursday, March 31, 2005

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

Re: drop-down menu selected value Kjazwilty at 14:54 on Thursday, March 31, 2005

<option value="3" selected>Economy</option>

<%
...
if(selected check) Response.Write(" selected")
....

Re: drop-down menu selected value Kjazwilty at 14:57 on Thursday, March 31, 2005


and...

http://www.w3schools.com
http://www.w3.org

+ google and so forth .. ;-P



Re: drop-down menu selected value navyjax2 at 00:07 on Tuesday, April 14, 2009

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" />



Re: drop-down menu selected value navyjax2 at 06:07 on Monday, January 17, 2011

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




Re: drop-down menu selected value navyjax2 at 06:07 on Monday, January 17, 2011

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











CodeToad Experts

Can't find the answer?
Our Site experts are answering questions for free in the CodeToad forums








Recent Forum Threads
matrix addition
Re: Storing data from HTML to Excel or TXT
Re: function within loop problem
Re: Ô‡´ò¥¯¥é¥Ö¤Ï ¥Æ©`¥é©`¥á¥¤¥É£ò£±£±¥¢¥¤¥¢¥ó ¤Î£··¬ ¤Ç¤¹
Re: Replace
Re: タイトリスト AP2アイアン 712�情�
Re: SMS from Perl using HTTP request
Re: Charl Schwartzel
Re: Adhyayan - Annual Student Conference and Online Coding Festival


Recent Articles
ASP GetTempName
Decode and Encode UTF-8
ASP GetFile
ASP FolderExists
ASP FileExists
ASP OpenTextFile
ASP FilesystemObject
ASP CreateFolder
ASP CreateTextFile
Javascript Get Selected Text


Copyright codetoad.com 2001-2013