473,385 Members | 1,610 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,385 software developers and data experts.

clear an html SELECT and next insert in it all the elements of an array

how can clear an html SELECT and next insert in it all the elements of an array ()
I try this but seems doesn't works.

function ComboAddArrayValueWithLabel(combo,ArrayLabel,Array Value)
{
combo.options.length = 0;
for (i=0; i<ArrayLabel.length; i++)
combo.options[combo.options.length] = new Option(ArrayLabel[i],ArrayValue[i]);
}

Jul 23 '05 #1
1 10102
SAN CAZIANO wrote:
how can clear an html SELECT and next insert in it all the
elements of an array ()I try this but seems doesn't works.
function
ComboAddArrayValueWithLabel(combo,ArrayLabel,Array Value){combo.options.length
= 0;for (i=0; i<ArrayLabel.length; i++)
combo.options[combo.options.length] = new
Option(ArrayLabel[i],ArrayValue[i]);}


It's usually best to provide a complete example that demonstrates
the problem you are experiencing, and a complete explanation of
the behavior you are experiencing, and how it differs from the
behavior you are expecting (<url:
http://www.physci.org/codes/sscce.jsp />). For example:

<form name="myForm">
<select name="mySelect">
<option value="1">one</option>
<option value="2">two</option>
<option value="3">three</option>
</select>
<input type="button" name="myTest"
value="Test"
onclick="test(this.form.elements['mySelect'], labels,
values);">
</form>
<script type="text/javascript">
var labels = [
'four', 'five', 'six'
];
var values = [
4, 5, 6
];

function test(combo, ArrayLabel, ArrayValue) {
combo.options.length = 0;
for (var i = 0; i < ArrayLabel.length; ++i) {
combo.options[combo.options.length] =
new Option(ArrayLabel[i], ArrayValue[i]);
}
// combo.options[0].selected = true;
}
</script>

Works as shown in IE 6.0.2800, Firefox 1.0, Opera 7.54 and
Netscape 4.78 (if you uncomment the last line of -test-).

--
Grant Wagner <gw*****@agricoreunited.com>
comp.lang.javascript FAQ - http://jibbering.com/faq

Jul 23 '05 #2

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

Similar topics

2
by: Jas | last post by:
I want an ASP page with a dropdown and a simple button. Every time the user chooses an item from the dropdown and clicks on the button i want that value written below in list and allow user to...
12
by: Kevin Lyons | last post by:
Hello, I am trying to get my select options (courses) passed correctly from the following URL: http://www.dslextreme.com/users/kevinlyons/selectBoxes.html I am having difficulty getting the...
22
by: Luke | last post by:
Elements with name attribute: form, input, textarea, a, frame, iframe, button, select, map, meta, applet, object, param, img (if you know more reply...) Methods of addresing html elements:...
21
by: StriderBob | last post by:
Situation : FormX is mdi child form containing 2 ListViews ListView1 contains a list of table names and 4 sub items with data about each table. ListView2 contains a list of the columns on each...
19
by: Krishanu Debnath | last post by:
Hello, I have a call to hash_map::clear() function which takes long time. someClass::someFunction() { // typedef hash_map<name_id, uintMp; // Mp p; // assuming proper namespace, hash...
2
by: justplain.kzn | last post by:
Hi, I have a table with dynamic html that contains drop down select lists and readonly text boxes. Dynamic calculations are done on change of a value in one of the drop down select lists. ...
9
by: Jess | last post by:
Hello, I tried to clear a vector "v" using "v.clear()". If "v" contains those objects that are non-built-in (e.g. string), then "clear()" can indeed remove all contents. However, if "v"...
35
by: Lee Crabtree | last post by:
This seems inconsistent and more than a little bizarre. Array.Clear sets all elements of the array to their default values (0, null, whatever), whereas List<>.Clear removes all items from the...
5
aas4mis
by: aas4mis | last post by:
I haven't had much luck with specific controls, their properties and loops in the past. I thought I would share this tidbit of code, feel free to modify/modularize in any way to suit your needs. This...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
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...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

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.