December 3, 2010
jQuery Load form elements through ajax, from onchange event of drop down box
Question by miojamo
I have dropdown and need to dynamical load form elements based on statement
<select name="type" id="type">
<option value="1">input</option>
<option value="2">text</option>
</select>
case 1 load some form elements (inout etc..)
case 2 clear these elements
…
Thanks
Answer by andres descalzo
try this:
$(function() {
$('#type').bind('change', function(ev) {
var value = $(this).val();
$.ajax({
...
data: {valueType: value, html: encodeURIComponent($("#addhtml").html())},
...
});
});
});
Answer by Starx
We may want to try this also
$("#type").change(function() {
$.post(
"yourRequestHandlingPage.php",
{
param: $(this).val();
},
function(data) {
//supposing data holds the html output of dynamically creawted form element
$(".myformcontent").append(data); //add the elements at the end of the form elemetn
}
});