Click here to Skip to main content
15,891,253 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I want to pass value of selected option to onchange function of selectbox, which I make it dynamicly with javascript, how can i do this?
I make select box when the page is loading as follow :
C#
var div = document.createElement("form");
                div.setAttribute("name","frmtag");
                mainC.appendChild(div);

                var sel = document.createElement("select");
                sel.setAttribute("id","sel");
                sel.setAttribute("name","tag");
                div.appendChild(sel);

                var o = document.createElement('option');
                o.value = "All";
                o.text =  "All";
                sel.add(o);


during loading page other options are add to the select box.


if I dont add the select box dynamicly i can add function to onchange event as follow:

XML
<select name="tag" id="sel" onchange="addingBlog(this.value,'1')">
                <option value="All">All</option>
            </select>
Posted
Updated 2-May-14 8:56am
v2
Comments
DamithSL 2-May-14 10:18am    
can you update the question with how you create your dynamic control?
Coder93 2-May-14 14:57pm    
I update my question.

like below

JavaScript
mydynamic_select.setAttribute("onchange", function(){GetValue(alert(mydynamic_select_id);});
 
Share this answer
 
v2
I solve it with jquery :
C#
$('#sel').change(function(){
                    addingBlog ($(this).val(),'1');
                    });
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900