Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Populate Drop Down List

Posted on 2010-09-12
3
Medium Priority
?
486 Views
Last Modified: 2013-11-19
I simply need to populate a Drop Down List per an incoming Switch Value.

what is the syntax for adding a DROP DOWN OPTION to an existing list by ID?
to replace all in the list by the ID?

See skeleton below...
EXAMPLE HTML:

<select name="form_transaction_new.booking.medium_timing_id" id="form_transaction_new.booking.medium_timing_id">
 <option value="nan">Select Medium Timing</option>

</select>

Open in new window

0
Comment
Question by:SMabs
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 82

Accepted Solution

by:
leakim971 earned 2000 total points
ID: 33658510
Check this : http://www.w3schools.com/jsref/met_select_add.asp

You may use :

      function insertOption(id, value, text) {
            var option = document.createElement('option');
            option.text = text;
            option.value = value;
            var select = document.getElementById(id);
            try { select.add(option,null); } catch(ex) { select.add(option); }
      }

Test page :


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<script language="javascript">
	function insertOption(id, value, text) {
		var option = document.createElement('option');
		option.text = text;
		option.value = value;
		var select = document.getElementById(id);
		try { select.add(option,null); } catch(ex) { select.add(option); }
	}
</script>
</head>
<body onload="insertOption('form_transaction_new.booking.medium_timing_id', 'myValue', 'myText');">
<select name="form_transaction_new.booking.medium_timing_id" id="form_transaction_new.booking.medium_timing_id">
	<option value="nan">Select Medium Timing</option>
</select>
</body>
</html>

Open in new window

0
 

Author Comment

by:SMabs
ID: 33658574
thanks!
0
 
LVL 82

Expert Comment

by:leakim971
ID: 33659424
You're welcome! Thanks for the points!
0

Featured Post

Build and deliver software with DevOps

A digital transformation requires faster time to market, shorter software development lifecycles, and the ability to adapt rapidly to changing customer demands. DevOps provides the solution.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article discusses how to create an extensible mechanism for linked drop downs.
A while back, I ran into a situation where I was trying to use the calculated columns feature in SharePoint 2013 to do some simple math using values in two lists. Between certain data types not being accessible, and also with trying to make a one to…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

704 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question