We help IT Professionals succeed at work.

create textarea on the fly

jbrizal
jbrizal asked
on
Medium Priority
282 Views
Last Modified: 2012-06-27
hi .. I want to create a page which can be dynamic to add new textarea (or something else object) ..and can remove to that textarea ..

this is my code ..I don't know is correct way or not but ..can someone help me to fix it  or teach me  to develop in the right way ..

in this code i alredy succes to add and remove but when I submit this page ..nothing ..to send to next page and can not get the value from textarea that i have been create ??

<SCRIPT>
function removeElement(a)
{
  a.removeNode(true);
}

function fnAppend(){
  ctl = parseInt(document.test.ctl.value);  
  ctl+=1;
  document.test.ctl.value = ctl;    
  var oNewNode = document.createElement("OL");
 
  oList.appendChild(oNewNode);
  str='<p id="div' + ctl + '"><textarea name="aaa' + ctl +'"></textarea><br><textarea name="bbb' + ctl + '"></textarea><br><textarea name="ccc' + ctl + '"></textarea><input type="button" name="hd' + ctl + '" value="   ' + ctl + '   " onclick="removeElement(div' + ctl + ')"></div>';
  oNewNode.innerHTML = str
   
}
</SCRIPT>
<BODY>
<form name="test" action="abc.asp" method="get">
<UL ID = oList>
<input type="hidden" value="0" name="ctl">
<INPUT TYPE = "button" VALUE = "Append Child" onclick = "fnAppend()">
<INPUT TYPE = "submit" VALUE = "submit">
</form>  
</BODY>

 
Comment
Watch Question

Top Expert 2013
Commented:
It does not get submitted because it is not part of the form.  It is a standalone textarea.  It might work if you rewrite the innder HTML of the form with the textarea included.  

str=document.test.innerHTML;
str+=you new element here;
document.test.innerHTML=str;

That might work.  or you might have to put the whole form inside a Div and rewrite the innerHTML for that.

Cd&

Author

Commented:
thx u ..Cd& .. you have correct my page .. but I want to ask to you  if I have 2 tables ... and I want to insert this textarea on the 1 table ..can possible or not ??

<table1 id="tbl1">
.
. --- > insert to here ???
.
.
</table1>

<table2 id="tbl2">
.
.
.
.
</table2>
Top Expert 2013

Commented:
Hmmm....

I give a top quality answer quickly and you grade it B?  

...and you ask for additional help.  

You'll find that grading like that will make top-experts reluctant to help you, but
to answer the followup:

Just put a div in the cell where you want to put the textarea, and then re-write the
innerHTML of the div.

In the future I would recommend that when you intend to give less than an A grade you
let the expert know what you need for it to be an A and give them a chance to improve
the answer.

Cd&

Explore More ContentExplore courses, solutions, and other research materials related to this topic.