Need help on this one, I have this code where i intend to use, it adds a new textarea each time a button is clicked. How can i assign a unique element name for each textarea created? - <script type="text/javascript">
-
function addTextArea()
-
{
-
var newInput = document.createElement("textarea");
-
newInput.setAttribute("type", "text");
-
newInput.setAttribute('id','idName');
-
newInput.setAttribute('name','name');
-
newInput.setAttribute("cols", "50");
-
newInput.setAttribute("row", "30");
-
document.getElementById("divToAddTextBox").appendChild(newInput);
-
}
-
</script>
-
<body>
-
<form name ="reg" method="POST" action="sample_a.php">
-
<table><tr><td id="divToAddTextBox" width="400">
-
</td></tr>
-
<input type="button" onclick="addTextArea()" value="Click Here to Add Textbox" />
-
<input type="button" onclick="submit()" value="Click Here Submit" />
-
</table>
-
</body>
5 1286
Need help on this one, I have this code where i intend to use, it adds a new textarea each time a button is clicked. How can i assign a unique element name for each textarea created? - <script type="text/javascript">
-
function addTextArea()
-
{
-
var newInput = document.createElement("textarea");
-
newInput.setAttribute("type", "text");
-
newInput.setAttribute('id','idName');
-
newInput.setAttribute('name','name');
-
newInput.setAttribute("cols", "50");
-
newInput.setAttribute("row", "30");
-
document.getElementById("divToAddTextBox").appendChild(newInput);
-
}
-
</script>
-
<body>
-
<form name ="reg" method="POST" action="sample_a.php">
-
<table><tr><td id="divToAddTextBox" width="400">
-
</td></tr>
-
<input type="button" onclick="addTextArea()" value="Click Here to Add Textbox" />
-
<input type="button" onclick="submit()" value="Click Here Submit" />
-
</table>
-
</body>
try this: -
var count = 1;
-
function addTextArea()
-
{
-
var newInput = document.createElement("textarea");
-
newInput.setAttribute("type", "text");
-
newInput.setAttribute('id','textarea' + count);
-
newInput.setAttribute('name','textarea' + count);
-
newInput.setAttribute("cols", "50");
-
newInput.setAttribute("row", "30");
-
document.getElementById("divToAddTextBox").appendChild(newInput);
-
count++;
-
}
-
** make sure your script tag is between the head tag.
so now every textarea is called the same just with a different number at the end, makes it easier to read after cuz then u can use a for loop.
good luck.
big thanks epots9... one last thing, what if i would like to limit the number of textarea that can be added, where can i place the control?
big thanks epots9... one last thing, what if i would like to limit the number of textarea that can be added, where can i place the control?
a simple if statement can be used for that: -
var count = 1;
-
function addTextArea()
-
{
-
if(count >= 5)
-
{
-
alert("too many");
-
}
-
else
-
{
-
var newInput = document.createElement("textarea");
-
newInput.setAttribute("type", "text");
-
newInput.setAttribute('id','textarea' + count);
-
newInput.setAttribute('name','textarea' + count);
-
newInput.setAttribute("cols", "50");
-
newInput.setAttribute("row", "30");
-
document.getElementById("divToAddTextBox").appendChild(newInput);
-
count++;
-
}
-
}
-
good luck
that gives me something to start with, thanks a lot epots9.
np, i'm glad i could help
if u have anymore questions u can always come back to TSDN for support.
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Amir Hardon |
last post by:
I'm new to DOM and can't figure out this thing:
I'm trying to add a row to a table with a form field in one
of it's cells, but if I'm appending the field to a form
it gets out of the table. Can...
|
by: Adam Hartshorne |
last post by:
Hi All,
I have the following problem, and I would be extremely grateful if
somebody would be kind enough to suggest an efficient solution to it.
I create an instance of a Class A, and...
|
by: crjunk |
last post by:
I have 4 TextBoxes on my form that I'm trying to add together to get a
grand total. Here is the code I'm using:
<SCRIPT LANGUAGE="JavaScript">
<!-- Beginning of JavaScript -
function...
|
by: Michelle |
last post by:
I have a div that is initially empty. Clicking on a button will add some
text boxes and other controls so the user can add additional records. In
IE
all works fine but in Netscape 7.0 when I add...
|
by: yawnmoth |
last post by:
I'm having some difficulty with adding elements to a webpage via the
DOM. The following works:
main.htm:
<script>
js = document.createElement('script');
js.src='test.js';...
|
by: Paul_Madden via DotNetMonster.com |
last post by:
Basically I have a listbox to which I add simple STRING items- I have a
progress bar which I increment whenever I populate another portion of the
complete set of items I wish to add. What I observe...
|
by: Ken Fine |
last post by:
In code, I'm adding javascript attributes to form elements on an ASP.NET
page:
body.Attributes.Add("onClick", "highlight(event);");
body.Attributes.Add("onKeyUp", "highlight(event);");...
|
by: omerbutt |
last post by:
AJAX PROB WITH MULTIPLE RECORDS
helo iam having problem in ma code will any body look out an help, i am trying t add sale record in the database and the checkthe quantity of the part slod and...
|
by: santiago |
last post by:
I guess one cannot do this:
arraytot = arraytot + arraydet;
So, what's the trick to adding arrays like this?
Thanks.
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
| |