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

how to get the length of the choice box

i want to find the length of the choice box.....i,e to find how many options are present in the choice box...
for example if the number of options in the choice box is 4 then we have to find that the length of the choice box as 4 by using some javascript code....

Thanx in advance
Mar 18 '08 #1
3 1253
gits
5,390 Expert Mod 4TB
give your select node an id and use childNodes.length like this:

Expand|Select|Wrap|Line Numbers
  1. function get_child_nodes_length(id) {
  2.     var sel_node = document.getElementById(id);
  3.     return sel_node.childNodes.length;
  4. }
  5.  
kind regards
Mar 18 '08 #2
thanx for ur reply.....i will give u my javascript code plz help me.

Expand|Select|Wrap|Line Numbers
  1. function refresh()
  2. {
  3.  
  4.     var indexOfcombobox = document.form1.drughid.value;
  5.     sel = document.form1.drug;
  6.     for (i=0; i<sel.options.length; i++) {
  7.         if (sel.options[i].text ==indexOfcombobox ) {
  8.             sel.selectedIndex = i;
  9.             }
  10.     }
  11. }
Here drug is the name of the select box.
and Drughid is the name of the textbox.
and now i have to compare the value of the textbox with the option of the choice box.
And if the choice box option value becomes equal to the textbox value i have to set that index.
I call the refresh function on "<BODY onload="refresh()">"

can u suggest me any solution.
Actualy am geting error that
"sel.options .length" is null or not a object...

plz give me some solution...
Thanx in advance...
give your select node an id and use childNodes.length like this:

Expand|Select|Wrap|Line Numbers
  1. function get_child_nodes_length(id) {
  2.     var sel_node = document.getElementById(id);
  3.     return sel_node.childNodes.length;
  4. }
  5.  
kind regards
Mar 18 '08 #3
acoder
16,027 Expert Mod 8TB
Just set the value of the select box instead:
Expand|Select|Wrap|Line Numbers
  1. function refresh()
  2. {
  3.     var indexOfcombobox = document.form1.drughid.value;
  4.     document.form1.drug.value = indexOfcombobox;
  5. }
Mar 19 '08 #4

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

Similar topics

8
by: John Smith | last post by:
Hi, I'm writing a library in C++ which is supposed to be used by people using C. One function I have must return a string to users which is arbitrary length. The user must be able to use this...
13
by: MLH | last post by:
I have a form with two controls: !! - combo box !! - text box A button on the form tries to run this SQL when clicked... INSERT INTO BodyMsgsSent (ToWhom, BodyText) SELECT DISTINCTROW !! AS...
10
by: Lyle Fairfield | last post by:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vbaac11/html/acfctNZ_HV05186465.asp "If the value of the variant argument is Null, the Nz function returns the number zero or a...
16
by: sotirac | last post by:
Wondering if there is a better way to generate string of numbers with a length of 5 which also can have a 0 in the front of the number. <pre> random_number = random.sample(, 5) # choose 5...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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.