Solved

Populate Drop Down List

Posted on 2010-09-12
3
473 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
  • 2
3 Comments
 
LVL 82

Accepted Solution

by:
leakim971 earned 500 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Windows Tool to Build Android and iOS App 3 51
Working with SharePoint Data 8 46
Allow space in this pattern 2 46
insert text field data into html script 13 18
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
JavaScript has plenty of pieces of code people often just copy/paste from somewhere but never quite fully understand. Self-Executing functions are just one good example that I'll try to demystify here.
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

932 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now