Solved

Populate Drop Down List

Posted on 2010-09-12
3
470 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
Comment Utility
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
Comment Utility
thanks!
0
 
LVL 82

Expert Comment

by:leakim971
Comment Utility
You're welcome! Thanks for the points!
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Introduction Knockoutjs (Knockout) is a JavaScript framework (Model View ViewModel or MVVM framework).   The main ideology behind Knockout is to control from JavaScript how a page looks whilst creating an engaging user experience in the least …
Introduction Since I wrote the original article about Handling Date and Time in PHP and MySQL (http://www.experts-exchange.com/articles/201/Handling-Date-and-Time-in-PHP-and-MySQL.html) several years ago, it seemed like now was a good time to updat…
HTML5 has deprecated a few of the older ways of showing media as well as offering up a new way to create games and animations. Audio, video, and canvas are just a few of the adjustments made between XHTML and HTML5. As we learned in our last micr…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. 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.: (CODE)

744 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

15 Experts available now in Live!

Get 1:1 Help Now