2

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/

user2779065
  • 175
  • 1
  • 2
  • 15

1 Answers1

1

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'));
});
Community
  • 1
  • 1
Alex
  • 9,911
  • 5
  • 33
  • 52
  • sorry, i am not not familiar with jquery. can u please guide me how to put this up – user2779065 Nov 13 '13 at 17:02
  • why did you use it as a tag then? sorry but this is little bit of a time killer right now – Alex Nov 13 '13 at 17:04
  • 1
    @user2779065 Read up on how to use `$(document).ready()` as [shown here](http://learn.jquery.com/about-jquery/how-jquery-works/). Put Alex's code inside a ready block and remove your manual `onclick` handlers. Of course, this all assumes you're including jQuery in your page (as implied by using the `jQuery` tag). If you're not / don't know what we mean, [read this](http://www.w3schools.com/jquery/jquery_install.asp) – Basic Nov 13 '13 at 17:12