user2779065
user2779065

Reputation: 183

prevent button to reset textbox value

I am trying to create mcq question and able to add the question. but the problem appear when i already fill the textbox and when i press the add question button, the textbox value always disappear.

<form name="newdocument">

            <div id="questions" data-role="fieldcontain"><input type="text" value="dsa"/></div>
            <input type="button" value="Add Question" onclick="AddQuestion();" />

        </form>

the javascript code is on http://jsfiddle.net/Xv3Xq/1/

Upvotes: 2

Views: 927

Answers (1)

Alex
Alex

Reputation: 10226

Dont use innerHtml+=, its bad. The stuff you write in an input field will get erased, since its not considered when using innerHtml but rather erased. Use jQuery! Something like:

$('#addQuestion').click(function() {
  $('<input />').appendTo($('#questions'));
});

Upvotes: 1

Related Questions