Я пытаюсь показать форму динамически в соответствии с запросом.Добавить/удалить элемент html динамически
HTML
<label for="Type" class="required">Type</label>
<br>
<input id="f01" name="fieldid[]" type="hidden" value="23">
<input class="23" id="01" required="1" name="type" type="checkbox" value="g_magic"><span> G magic</span>
<div>
<div id="div0g_magic"></div>
</div>
<input id="f02" name="fieldid[]" type="hidden" value="23">
<input class="23" id="02" required="1" name="type" type="checkbox" value="four_five"><span> Four five</span>
<div>
<div id="div0four_five"></div>
</div>
</div>
JAVASCRIPT
$("#01").on("change", function() {
var valueid = $("#01").val();
var fieldid = $("#f01").val();
if ($(this).is(":checked")) {
send(valueid, fieldid);
} else {
$("#div0" + valueid).empty();
}
});
function send(valueid, fieldid) {
$.ajax({
url: '/echo/js/?js=hello%20world!',
success: function (response) {
$("#div0" + valueid).html(response.responseText);
},
error: function (response) {
$("#div0" + valueid).html(response);
}
});
}
$("#02").on("change", function() {
var valueid = $("#02").val();
var fieldid = $("#f02").val();
if ($(this).is(":checked")) {
send(valueid, fieldid);
} else {
$("#div0" + valueid).empty();
}
});
function send(valueid, fieldid) {
$.ajax({
url: '/echo/js/?js=hello%20JS!',
success: function (response) {
$("#div0" + valueid).html(response.responseText);
},
error: function (response) {
$("#div0" + valueid).html(response);
}
});
}
CSS
.required:after {
color: #e32 !important;
content: ' * ' !important;
display: inline !important;
}
Где мой код? –
Ваш код – Tanmay
Вы забыли включить ссылку своего кода в свой вопрос – xzegga