0

I have defined a drop down list in html as follows. I have appended the values for the dropdown from javascript. The value I am trying to set is "5". But it does not work. Can someone tell me another way?

<html>
<head>
<title>Title</title>
<script type="text/javascript" src="phonegap-1.4.1.js"></script>
<script type="text/javascript" src="JS/Util.js"></script>
<script type="text/javascript" src="JS/Language.js"></script>
<script type="text/javascript"> 
function dropdown(){
document.getElementById("numberlist").appendChild(5);
}
</script>
</head>

<body onload="dropdown();">
<div id="main3"></div>

<select id = "numberlist"><option>12</option><option>24</option><option>36</option></select>

</body>

</html>
3
  • 1
    Which option you want to set to 5? Commented Jun 28, 2012 at 6:44
  • I want to add it to the options. As a new value. Commented Jun 28, 2012 at 6:45
  • follow this w3schools.com/jsref/met_select_add.asp Commented Jun 28, 2012 at 6:47

1 Answer 1

2

Copying from the original question. Will this solve your issue?

function dropdown(){ 
var drp = document.getElementById("numberlist");
var optn = document.createElement("OPTION"); 
optn.text="3";  
optn.value="3";   
drp.add(optn);
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.