Solved

Populate Drop Down List

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

Why Off-Site Backups Are The Only Way To Go

You are probably backing up your data—but how and where? Ransomware is on the rise and there are variants that specifically target backups. Read on to discover why off-site is the way to go.

Question has a verified solution.

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

International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
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?
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
Suggested Courses

617 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