473,786 Members | 2,451 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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="javas cript" type="text/javascript">
function ordering(sorder )
{
var link = document.getEle mentById("mylin k").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">Cre ate PDF</option>
<option value="http://www.mysite.com? Option=bylaws"> Bylaws</option>
</select>

Jun 22 '06 #1
1 1835
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">Cre ate 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.getEle mentById("menu" );
var options = menu.getElement sByTagName("opt ion");

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

options[menu.selectedIn dex].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
3673
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 select.length = 0 (on filled element) lasts for few seconds. ok. i have large amount of data to preload, and i also do some operations on that data, but it's all very fast. so i thought it must be some IE rendering issue, and i tried to set...
3
2661
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 to say how many elements it will contain. In Java there exists special containers to achieve that, but what about VB? I thought about somethign like that: select year from db
3
1947
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 echo $init_text ; ?> </TEXTAREA>
4
19627
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
12558
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 = window.document.forms.srcList;
4
1749
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 correctly but not the text. Thanks Desired end result: <select id="selectBox" multiple="multiple" size="4"> <option value="Div3">About the Company</option> <option value="Div1">Ratings</option>
1
1965
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 </option> <option250 to 300</option> <option 300 </option> </select>
3
22291
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 are so many things not possible with select boxes in IE. But the I discovered I could actually change the height by adjusting font-size, then adjusting height I was actually able to tweak the height.
0
1377
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 project where I am feeding in nightly a set of values from an external data source, and populating my form with those values. In the end, I end up resending a new query to this datasource with a custom url, including as parameters the values...
0
9647
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9492
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10163
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10108
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9960
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8988
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6744
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5397
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
3
2894
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.