javascript - Displaying Dynamic Content With JS
I have a dropdown on a Page as follows, when the user selects a dropdown - I need for a different form to be produced underneath eg:
<div id = 'drop'>
<select name = 'option'>
<option>Opt1</option>
<option>Opt2</option>
<option>Opt3</option>
</select>
</div>
<div id = 'NewContent'>
//I need different content here depending on selection
</div>
How could I load a different form into the new Content div for each different option a user selects?
to expand on the question say I had a form:
<form id ='TestForm'>
First name: <input type="text" name="firstname"><br>
Last name: <input type="text" name="lastname">
</form>
how would I use this:
$('select[name="option"]').change(function() {
$('#NewContent').html(this.value);
});
to add the form as seen above?
Answer
Solution:
Try this way : Fiddle link
Answer
Solution:
You can use
$('#NewContent').html('Some New Content');
to change the content using JQueryMore information is available here.
Answer
Solution:
You can use .change() event:
Fiddle Demo
Answer
Solution:
As you mentioned in your post:
I need for a different form to be produced underneath
and change the form id like this:
Fiddle