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/

1
  • why arent you using jQuery? Commented Nov 13, 2013 at 16:52

1 Answer 1

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'));
});
Sign up to request clarification or add additional context in comments.

3 Comments

sorry, i am not not familiar with jquery. can u please guide me how to put this up
why did you use it as a tag then? sorry but this is little bit of a time killer right now
@user2779065 Read up on how to use $(document).ready() as shown here. 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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.