473,326 Members | 2,125 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,326 software developers and data experts.

Changing Value of a Selectbox

I've been using this little script to change the <a href=""></a> value
of a link which works well.

<script language="javascript" type="text/javascript">
function ordering(sorder)
{
var link = document.getElementById("mylink").href =
"http://www.mysite.com?Option="+sorder;
}
</script>

<a id="mylink" href="http://www.mysite.com/">Create PDF</a>
I'm wondering how I would do the same thing to change the value in a
selectbox like this?

<select size="1" name="menu">
<option value="http://www.mysite.com?Option=reports">Reports</option>
<option value="http://www.mysite.com?Option=pdf">Create PDF</option>
<option value="http://www.mysite.com?Option=bylaws">Bylaws</option>
</select>

Jun 22 '06 #1
1 1805
shankwheat wrote:
I'm wondering how I would do the same thing to change the value in a
selectbox like this?

<select size="1" name="menu">
<option value="http://www.mysite.com?Option=reports">Reports</option>
<option value="http://www.mysite.com?Option=pdf">Create PDF</option>
<option value="http://www.mysite.com?Option=bylaws">Bylaws</option>
</select>


Well, first you're going to have to know *which* value you want to
change - in your example, there's three. On which do you want to operate?

You can get a collection of the option elements like this:

HTML:
<select size="1" name="menu" id="menu">
<option value="...">...</option>
...
</select>

Script:
var menu = document.getElementById("menu");
var options = menu.getElementsByTagName("option");

If you want to operate on whichever element is selected, try this:

options[menu.selectedIndex].value = "a new value";

Otherwise just pick the option you want by indexing it into the
collection, and change its value attribute to what you want.

Jeremy
Jun 22 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Tole | last post by:
hi all, i've got a selcetbox (multiple) which is filled by javascript. only problem is that i have aprox 1000 options to add to that select, and that adding lasts for 5-6 seconds. Even...
3
by: Stefan Richter | last post by:
I would like to fill a Selectbox dynamically. I am taking all values from a db, and fill them into a selectbox. I guess the best way was to use some kind of a dynamical array, where you don't have...
3
by: phdfromic | last post by:
I want to set an initial text in a TEXTAREA based on the value selected in an earlier SELECT box in the same document. I tried something like $init_text=set_init_text() ; <TEXTAREA> <?php...
4
by: Robert Bravery | last post by:
HI all, In JS, how can I change the selected value of a dropdownlist(select options) I know the value of indexed value of the selected value before it is changed. Thanks Robert
3
by: imrantbd | last post by:
This is my first problem.Please help me. I have the following code: <head> <script language="JavaScript"> function addSrcToDestList() { destList1 = window.document.forms.destList; srcList...
4
by: shankwheat | last post by:
I'm passing a string like 'Div3,Div4' to use as options in a selectbox but I need the text the user sees in the box different from the values. My code populates the values in the selectbox...
1
by: giloosh | last post by:
i would like to dynamically output such a selectbox below using php and mysql: <select> <option< 100 </option> <option100 to 150 </option> <option150 to 200 </option> <option200 to 250...
3
by: =?iso-8859-1?q?Jesper_R=F8nn-Jensen?= | last post by:
I'm working with a requirement to make a selectbox the same height as normal text input elements. (at least for IE7) But in IE the selectbox reacts strangely to the CSS rules. Normally, there...
0
by: jonKushner | last post by:
id like to create a script that runs through a form, and autogenerates every single permutation for every single value, as well as option. The task is because I am currently working on a webservice...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.