A friendly place for programming greenhorns!
Big Moose Saloon
Search
|
Java FAQ
|
Recent Topics
Register / Login
Win a copy of
The Mikado Method
this week in the
Agile and other Processes
forum!
JavaRanch
»
Java Forums
»
Engineering
»
HTML, CSS and JavaScript
Author
Assign a value to a Option In a Select dropdown on the fly
samuel marin
Greenhorn
Joined: Nov 18, 2011
Posts: 7
posted
Nov 18, 2011 13:43:39
0
I have a function that creates a Select dropdown on the fly:
function makeForm() { mypara=document.getElementById("paraID"); myform=document.createElement("form"); myselect = document.createElement("select"); theOption=document.createElement("OPTION"); theText=document.createTextNode("Revenue"); theOption.appendChild(theText); myselect.appendChild(theOption); myform.appendChild(myselect); mypara.appendChild(myform); myselect.onchange=TitleOnChange; mybreak=document.createElement("p"); myform.appendChild(mybreak); }
I would guess that I have to add something like:
theOption.setAttribute("value","1");
I want to be able to call the following function and execute a code base on the selection of the Select Dropdown:
<script type='text/javascript'> function TitleOnChange() { if (document.form.select.value == "1") { alert("Value selected on the Select dropdonw is 1"); } } </script>
I don't know why is not working. I assigned the value 1 to the select dropdown
theOption.setAttribute("value","1");
I call the TitleOnChange function
myselect.onchange=TitleOnChange;
And Finally I indicate that if the value is equal to 1 do...
if (document.form.select.value == "1") { alert("Value selected on the Select dropdonw is 1"); }
Does anyone knows why this doesn't work and how could I fix it?
Any helpt would be highly appreciate.
Thanks
Bear Bibeault
Author and ninkuma
Marshal
Joined: Jan 10, 2002
Posts: 56185
13
I like...
posted
Nov 18, 2011 13:56:50
0
Please do not post the same question more than once.
[
Smart Questions
] [
JSP FAQ
] [
Books by Bear
] [
Bear's FrontMan
] [
About Bear
]
I agree. Here's the link:
http://zeroturnaround.com/jrebel
- it saves me about five hours per week
subject: Assign a value to a Option In a Select dropdown on the fly
Similar Threads
get all from select multiple
Recognizing a Form
How to call a function within a function.
How to Assign a value to a Option of a Combo on the fly
How to get values from a dropdownlist
All times are in JavaRanch time: GMT-6 in summer, GMT-7 in winter