I am writing a JSP page where an admin can prepare the question format for the users. All the questions have multiple choices ranging from 2 (for yes or no) to 5. I want to provide a button for the admin which on click has to generate a text box corresponding to 1 answer. This button should also check that the answer boxes have not exceeded 5 as there can be no more than 5 multiple choices.
How can I go about this problem? How to stuff the JavaScript variable inside the innerHTML
? I have done something like this:
function addAnswer(queryNum, ansCount){
var d=document.getElementById("div");
var i = queryNum;
alert(i);
var j = ansCount;
alert(j);
d.innerHTML+="<label class='optsurvey-answer' for='answer_'>Answer</label>"+"<input class='optsurvey-answerinput' type='text' name='<portlet:namespace />answer_'>";
}
</script>
Here queryNum
and ansCount
are params passed by JSP. I want to stuff them inside the d.innerHTML
. Something like this
d.innerHTML+="<label class='optsurvey-answer' for='answer_'>Answer<HERE I HAVE TO STUFF "ansCOUNT" ></label>"+"<input class='optsurvey-answerinput' type='text' name='<portlet:namespace />answer_'>";