473,385 Members | 1,445 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.

How to add new options in select options using JavaScript

how to add new more options in select box options using JavaScript . Please tell me what i do for add more options in options box using JavaScript .
Apr 10 '13 #1
5 6233
r035198x
13,262 8TB
Try

Expand|Select|Wrap|Line Numbers
  1. var newOption= document.createElement("OPTION");
  2. newOption.innerText = "yourText";
  3. newOption.value = "yourValue";
  4. document.yourForm.yourSelect.options.add(newOption);
Apr 10 '13 #2
acoder
16,027 Expert Mod 8TB
That looks like a very IE-specific way of adding options.

I would suggest a simple:
Expand|Select|Wrap|Line Numbers
  1. yourSelect.options[yourSelect.options.length] = new Option(text, value);
If using the add method, you'd need a try/catch block to deal with IE's non-standard implementation (probably been fixed in newer versions, but I haven't checked).
Apr 10 '13 #3
r035198x
13,262 8TB
Not to mention that
Expand|Select|Wrap|Line Numbers
  1. options[yourSelect.options.length] = new Option(text, value);
is much cleaner and simpler ...
Apr 10 '13 #4
Sherin
77 64KB
Try This Code

Expand|Select|Wrap|Line Numbers
  1. var min = 10,
  2.     max = 50,
  3.     select = document.getElementById('selectElementId');
  4.  
  5. for (var i = min; i<=max; i++){
  6.     var opt = document.createElement('option');
  7.     opt.value = i;
  8.     opt.innerHTML = i;
  9.     select.appendChild(opt);
  10. }
Feb 16 '21 #5
mirandapalmer
2 2Bits
I have the same problems. Thanks for share this.
Feb 16 '21 #6

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

Similar topics

1
by: Griff | last post by:
Hi! I'm using JavaScript on an HTML page for form validation. I have a form value (theForm.ProdType1) which represents a picklist from which users may make multiple selections; essentially,...
1
by: craig | last post by:
Hi, I've been asked to create a page that dynamically populates the contents of related drop down lists using JavaScript, and then obviously posts things back to the server. For completeness,...
7
by: pstiles | last post by:
I have a need to create a list in a textarea, some selected by clicking on a word, some typed in by user. I have tried many things to little avail. I can set the text in the texarea, but it will...
1
by: vehuel | last post by:
I have a select multiple (combobox) in a form and I need to select, using javascript, more than one item in this select. How can I do this?
2
by: simon.wilkinson | last post by:
Hi, I am trying to update all Select boxes on a page dynamically using javascript, I simple want to change the selected item in each select box when a tick box is pressed on the page. Each...
14
mikek12004
by: mikek12004 | last post by:
In a form I have 5 elements (e.g. pictures) and I wish for the user to be able to set the order of appearance. For this I have for each picture a select box (names select1 to select5) with "please...
2
by: askrk | last post by:
1.im using php programming.how to call a function using select button in form but no output has been shown........ 2.script page <script type="text/javascript"> function education_onchange() {...
1
by: moose hoss | last post by:
How would I validate this select box using JavaScript? <form action="pizza/data.php" method="post" name="form" onsubmit="javascript:return form_validation();"/> <select name="team"...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
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...
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
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
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...
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...

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.