Connecting Tech Pros Worldwide Help | Site Map

dynamic acess of objects problem

 
LinkBack Thread Tools Search this Thread
  #1  
Old July 20th, 2005, 11:24 AM
Brad Esclavon
Guest
 
Posts: n/a
Default dynamic acess of objects problem

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>



  #2  
Old July 20th, 2005, 11:24 AM
Lasse Reichstein Nielsen
Guest
 
Posts: n/a
Default 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.'
  #3  
Old July 20th, 2005, 11:24 AM
DU
Guest
 
Posts: n/a
Default 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

 

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Popular Articles

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over 220,989 network members.