dynamic acess of objects problem

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Brad Esclavon

    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(al so 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="JavaS cript">
    <!--
    // 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

    #2
    Re: dynamic acess of objects problem

    "Brad Esclavon" <gtg724h@mail.g atech.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(al so 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="JavaS cript">[/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/rasterTriangleD OM.html>
    'Faith without judgement merely degrades the spirit divine.'

    Comment

    • DU

      #3
      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.




      DU
      --
      Javascript and Browser bugs:

      - Resources, help and tips for Netscape 7.x users and Composer
      - Interactive demos on Popup windows, music (audio/midi) in Netscape 7.x


      Comment

      Working...