When a user doesn't fill the form completely. I want the unfilled input part to return as an empty string.
document.getElementById("skill2").defaultValue = '';
I tried using the above statement but the error comes up as
Cannot assign default value to null
If the form element isn't filled, I get the output as undefined.
I'm attaching a part of the code.
var experiment1 = function()
{
var skill2 = $("#skill2").val();
var html1='<p>'+skill2+'</p>';
return html1;
}
$("#bodytag").html(experiment1);
and Yeah, I'm using dynamically generating the form elements. I'm attaching a snippet of that code.
var count2 = 1;
var limit2 = 6;
function addInput2(divName){
if (count2 == limit2) {
alert("You have reached the limit of adding " + count2 + " skills");
}
else {
var newdiv = document.createElement('div');
newdiv.innerHTML = "<input type='text' name='myInputs[]' id='skill"+(count2+1)+"' style='width:100%;' value=' ' class='text-center' "+
"placeholder='skill"+(count2+1)+"'><br/><br/>";
document.getElementById(divName).appendChild(newdiv);
count2++;
}
}
So, the problem is, unless the user generates the element, in the output, the value will come as undefined.