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

how to clear the combo box values using javascript..?

nirmalsingh
218 100+
my combo box id is combo1, i want to clear the values that are loaded in combo box from database, plz help me with sample code..
Jan 4 '07 #1
7 27548
b1randon
171 Expert 100+
my combo box id is combo1, i want to clear the values that are loaded in combo box from database, plz help me with sample code..
Post some code that we can help you with...
Jan 4 '07 #2
nirmalsingh
218 100+
//my coding...
var strDetails;
var intLoop;
var strArrRow = new Array();
strDetails=xmlHttp.statusText;//records to load combo..
strArrRow =strDetails.split('|');
var x=document.getElementById("combo1");
for (intLoop=0;intLoop<strArrRow.length-1;intLoop++)
{
var y=document.createElement('option');
y.text=strArrRow[intLoop]
try
{
x.add(y, null);
}
catch(ex)
{
x.add(y);
}
}
Jan 5 '07 #3
r035198x
13,262 8TB
//my coding...
var strDetails;
var intLoop;
var strArrRow = new Array();
strDetails=xmlHttp.statusText;//records to load combo..
strArrRow =strDetails.split('|');
var x=document.getElementById("combo1");
for (intLoop=0;intLoop<strArrRow.length-1;intLoop++)
{
var y=document.createElement('option');
y.text=strArrRow[intLoop]
try
{
x.add(y, null);
}
catch(ex)
{
x.add(y);
}
}
I'm a bit confused here. Do you want to delete values from the database or do you want to clear options from a select box?
Jan 5 '07 #4
nirmalsingh
218 100+
sorry to make u confused sir, i want to clear the options from the select box. not from database.
Jan 5 '07 #5
r035198x
13,262 8TB
sorry to make u confused sir, i want to clear the options from the select box. not from database.
Well the general rule is if you have a select by the name box, then

To clear all options of box just do
box.options.length = 0;
Jan 5 '07 #6
b1randon
171 Expert 100+
Well the general rule is if you have a select by the name box, then

To clear all options of box just do
box.options.length = 0;
This is by far the best way to remove the options. If you try to remove them one by one in a loop you won't be able to remove the last option. I lost a good bit of hair before realizing that options.length=0; is all I needed :/
Jan 5 '07 #7
r035198x
13,262 8TB
This is by far the best way to remove the options. If you try to remove them one by one in a loop you won't be able to remove the last option. I lost a good bit of hair before realizing that options.length=0; is all I needed :/
I hope the hair grew back on.
Jan 6 '07 #8

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: mr_burns | last post by:
hi, using javascript, how do i select an option in a combo box? i have tried looking on the internet but dont really know what i should be searching for. what i want to happen is that when a...
2
by: Stephen Miller | last post by:
I have a page with many, dynamically generated combo boxes and I want to check all of them, before I add a unique value to specific combo. What would be the best way to work through the document...
1
by: SAN CAZIANO | last post by:
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,ArrayValue) { ...
5
by: Harry Haller | last post by:
<select name="cboPlaces" id="cboPlaces"> <option value="3">Countryside</option> <option value="4">Forest</option> <option value="5">Mountain</option> <option value="6">Desert</option> <option...
2
by: Eric Layman | last post by:
Hi, I have a radio button and a combo box. Upon changing a value for radio button, the combo box values will be dynamically updated. I have an idea on how to go abt doing it but Im stuck...
33
by: buss123 | last post by:
Hi all, combo box script code was working in IE perfectly with all modes but OnChange event was not working in FireFox(editable mode, if we select valuese that combo box values r...
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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...
0
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,...

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.