The below code is for creating checkbox dynamically.
But in Chrome console it says $ is not defined. This $ error is in this line:
$.post(
"index1.php",
{
"newopt": newopt
},
Full Code here...
var optiondiv = document.getElementById('option-div');
document.getElementById('create').onclick = function () {
newopt = document.getElementById('new-option').value;
if(newopt){
var input = document.createElement('input'),
label = document.createElement('label');
/* IF USER DID NOT INPUT A TEXT, 'No Entered Text' WILL BE THE DEFAULT VALUE */
newopt = (newopt == '')?'No Entered Text':newopt;
/* FILL OUT THE TAGS OF THE NEW INPUT ELEMENT */
input.type = "checkbox";
input.setAttribute("value", newopt);
input.setAttribute("checked", true);
input.setAttribute("name", "prints[]");
/* PUT THE INPUT ELEMENT/RADIO BUTTON INSIDE THE LABEL */
label.appendChild(input);
label.innerHTML += newopt+'<br>';
/* PUT THE LABEL ELEMENT INSIDE THE option-div DIV */
optiondiv.appendChild(label);
//optiondiv.appendChild(input);
//ele.appendChild(input);
//input.onclick = function(){ alert('this is test'); };
//optiondiv.appendChild(label);
document.getElementById('new-option').value = '';
$.post(
"index1.php",
{
"newopt": newopt
},
function(data) {
if(data.success){
alert('Successfully Added To dB');
}else{
alert('Not Added To DB');
}
});
}else{
alert('Please Enter Check Box Value.');
return false;
}
};