Solved

Populate Drop Down List

Posted on 2010-09-12
3
479 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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
alert(innerHTML); 8 32
how can i get 4 nd 5 ? 3 31
Load data upon clicking a button 8 35
100% tall div not scrollable on iPhone 3 20
Preface This is the third article about the EE Collaborative Login Project. A Better Website Login System (http://www.experts-exchange.com/A_2902.html) introduces the Login System and shows how to implement a login page. The EE Collaborative Logi…
Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).

828 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