html - How can I dynamically add and change divs in javascript? -


i have following code:

<!doctype html> <html> <head> <script type="text/javascript">  function timemsg() { var t=settimeout("enterquestion()",900000); }   function enterquestion() { document.getelementbyid("questions").innerhtml += '<p>'  + document.getelementbyid("question").value;   } </script> </head> <body>  <h1>testing website</h1> <p id="questions"></p>  <input type="text" name="question" id="question" /> <button type="button" onclick="timemsg()">enter question</button>   </body> </html>  

all code allows user enter question , adds question list of questions after 15 minutes have passed.

all i'd code make puts text "question recorded" in place question show up, instead of adding question end, should replace "question recorded" text question.

i can't figure out how in such way can enter multiple questions @ same time.

any appreciated,

thanks!

the innerhtml property handy when want replace entire content of element not adding or inserting child nodes. that, it's easier use createelement.

the following example going:

<script> function adddiv(parent, text) {   var div = document.createelement('div');   div.appendchild(document.createtextnode(text));   parent.appendchild(div); } </script>  <form action="serverprocess" onsubmit="return false;">   <input type="text" name="qtext" value="question text">   <button onclick="     adddiv(document.getelementbyid('container'), this.form.qtext.value);   ">add question</button> </form> <div id="container"></div> 

in above, if javascript isn't available or active, form submitted , processing can done on server. if it's available, processed locally , form won't submit, though submission should based on successful completion of actions.

i'll leave ponder.


Comments

Popular posts from this blog

java - Play! framework 2.0: How to display multiple image? -

gmail - Is there any documentation for read-only access to the Google Contacts API? -

php - Controller/JToolBar not working in Joomla 2.5 -