dynamic acess of objects problem

B

Brad Esclavon

i am creating a page that creates 10-45 text input areas dynamically in a
for loop. all the fields will be identical except for content, and i need a
button to clear each corresponding field individually(also dynamically
created). i have tried to do it various ways, but i cant get the proper
object declared, i always get object does not exist or object undefined
errors. I dont even know what this is called so that i can look it up. im
kind of lost as how to solve it.

below is my code

<script language="JavaScript">
<!--
// num is the number corresponding to the appropiate textarea
// function makeblank(num)
{
titlenum='txt' + num.toString();
var txt = document.form1.txtnum;
txt.value="";
}
//-->
</script>

<html>
<form name="form1" action="/admin/feedback.php" method="post">

<textarea name="txt1" style="width: 600px; height: 200px"></textarea>
<textarea name="txt2" style="width: 600px; height: 200px"></textarea>
<textarea name="txt3" style="width: 600px; height: 200px"></textarea>

</form>
</html>
 
L

Lasse Reichstein Nielsen

Brad Esclavon said:
i am creating a page that creates 10-45 text input areas dynamically in a
for loop. all the fields will be identical except for content, and i need a
button to clear each corresponding field individually(also dynamically
created). i have tried to do it various ways, but i cant get the proper
object declared, i always get object does not exist or object undefined
errors. I dont even know what this is called so that i can look it up. im
kind of lost as how to solve it.

below is my code
<script language="JavaScript">
It's

<!--

You don't need HTML comments in Javascript.
// num is the number corresponding to the appropiate textarea
// function makeblank(num)

This line shouldn't be commented out?
{
titlenum='txt' + num.toString();
var txt = document.form1.txtnum;

Is it "titlenum" or "txtnum"?
txt.value="";
}
//-->
</script>

What you probably need is:
---
<script type="text/javascript">
function makeblank(num)
{
document.forms['form1'].elements['txt'+num].value="";
}
</script>
 
D

DU

Brad Esclavon wrote:

<html>
<form name="form1" action="/admin/feedback.php" method="post">

<textarea name="txt1" style="width: 600px; height: 200px"></textarea>

I just wanted to add this to Lasse's excellent post.

rows and cols are required attributes in HTML 4 and in all other HTML
versions. These attributes are mandatory as they help browsers figure
out when/where to wrap text lines.
http://www.w3.org/TR/REC-html32#textarea
http://www.w3.org/TR/html401/interact/forms.html#edef-TEXTAREA


DU
--
Javascript and Browser bugs:
http://www10.brinkster.com/doctorunclear/
- Resources, help and tips for Netscape 7.x users and Composer
- Interactive demos on Popup windows, music (audio/midi) in Netscape 7.x
http://www10.brinkster.com/doctorunclear/Netscape7/Netscape7Section.html
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,432
Messages
2,571,681
Members
48,796
Latest member
Greg L.

Latest Threads

Top