I am adding Select/Option
based on the user input.
How do I write a jQuery that reacts to Select/Option
that is dynamically created based on user input.
Here is my jsfiddle, https://jsfiddle.net/tnc5bqpw/2/
I tried adding the simple jQuery to react to new Select/Option
whose id is selecta
. But this does not work.
// Select option for topic
$("#selecta").change(function() {
// varible to hold string
console.log("changed");
var str = "";
var val = "";
$("select option:selected").each(function() {
str += $(this).text() + " ";
val = $(this).val();
});
var divbox = document.getElementById('textbox');
divbox.innerHTML ="<span style='color:black; font-family:Georgia,serif;font-size:30px;font-style:regular;'>Selected"+ str+"</span>";
console.log(str,val);
}).change();
Problem here :
I have a initial Select/Option
and user gets to select two options. And based on this selection, new Select/Option
is added to the page. I cannot figure out how can i added jQuery change
trigger to this new Select/Option
. Based on user's selection to this, page needs show other elements.