Connecting Tech Pros Worldwide Forums | Help | Site Map

dynamic acess of objects problem

Brad Esclavon
Guest
 
Posts: n/a
#1: Jul 20 '05
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>





Lasse Reichstein Nielsen
Guest
 
Posts: n/a
#2: Jul 20 '05

re: dynamic acess of objects problem


"Brad Esclavon" <gtg724h@mail.gatech.edu> writes:
[color=blue]
> 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[/color]
[color=blue]
> <script language="JavaScript">[/color]

It's
<script type="text/javascript">
in HTML 4 and later.
[color=blue]
> <!--[/color]

You don't need HTML comments in Javascript.
[color=blue]
> // num is the number corresponding to the appropiate textarea
> // function makeblank(num)[/color]

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

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

What you probably need is:
---
<script type="text/javascript">
function makeblank(num)
{
document.forms['form1'].elements['txt'+num].value="";
}
</script>
---
/L
--
Lasse Reichstein Nielsen - lrn@hotpop.com
DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleDOM.html>
'Faith without judgement merely degrades the spirit divine.'
DU
Guest
 
Posts: n/a
#3: Jul 20 '05

re: dynamic acess of objects problem


Brad Esclavon wrote:

[color=blue]
>
> <html>
> <form name="form1" action="/admin/feedback.php" method="post">
>
> <textarea name="txt1" style="width: 600px; height: 200px"></textarea>[/color]

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/interac...#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/doctorunc...e7Section.html

Closed Thread