views:

55

answers:

2

In a htmlpage using jquery or javascript how can the following be achieved?

User types in a question in a textarea and press on enter button ,then the same question should be displayed dynamically in the page below the textarea and the user can enter as many questions.

And when the user is done the page is submitted through a submit button

Can u please give a small hint of how this can be done..

Thanks..

A: 

Use the innerHTML property of a div to add the questions to.

Dave Anderson
+2  A: 

Try this to get started :

<!DOCTYPE html>
<html>
<head>
  <title>Example</title>
  <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.js"&gt;&lt;/script&gt;
  <script type="text/javascript">
    $(document).ready(function() {
      $('#textareabutton').click(function(){
        var q  = $('#textarea').val(),
            $p = $('<p>').html( q );
        $('#questions').append( $p );
      });
      $('#submit').click(function(){
        var tab;
        tab = $('#questions p').serializeArray();
        // now do something with $.ajax to submit the questions
        $.post("myphp.php",tab,function(resp){
          // what do I do with the server's reply ???
        });
      });
    });
  </script>
  <style type="text/css">
  </style>
</head>
<body>
  <textarea id='textarea'></textarea>
  <button type='button' id='textareabutton'>Add question</button>
  <div id='questions'></div>
  <button type='button' id='submit'>Submit questions</button>
</body>
</html>
David V.
Thanks....I will try this
Hulk