Results 1 to 4 of 4

Thread: JS and names in HTML

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Jan 2001
    Location
    Denmark
    Posts
    1,049

    Question JS and names in HTML

    How do I refer to a text field created like this?
    Code:
    <script language="JavaScript"><!--
    for (i=1;i<11;i++){
    document.write('   <td><input type=text name=t' + i + 'value=100></td>');
    	}
    //--></script>
    I have tried to use this
    var testing = formName.test.t2.value;
    does it not create 10 text fields with the names T1, T2 ... T10? Because that is how I want it to be.

  2. #2
    Fanatic Member punkpie_uk's Avatar
    Join Date
    Sep 2001
    Location
    UK
    Posts
    645
    Try this...

    Code:
    <script language="JavaScript"><!--
      for (i=1;i<11;i++){
        document.write('   <td><input type="text" name="t'+i +'" value="100"></td>');
        }
    //--></script>
    SPREAD THE WORD!!! Are You Lee McCormick? Because I Am



    Lee M McCormick
    [email protected]

    Lee McCormick.com - Live
    Dynamically Webbed.com - In development but live

  3. #3
    Black Cat JoshT's Avatar
    Join Date
    Nov 2000
    Location
    WNY, USA
    Posts
    4,032
    Further elaborating:

    Code:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
    	"http://www.w3.org/TR/html4/loose.dtd">
    			
    <html lang="en">
    <head>
    	<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
    	<meta http-equiv="Content-Script-Type" content="text/javascript">
    	<title>Untitled</title>
    </head>
    
    <body>
    <script language="JavaScript"><!--
      for (i=1;i<11;i++){
        document.write('   <td><input type="text" name="t'+i +'" value="100"></td>');
        }
    //--></script>
    <div onclick="alert(document.getElementsByName('t1').item(0).value);">CLICK HERE</div>
    </body>
    </html>
    Josh
    Get these: Mozilla Opera OpenBSD
    I have books for sale: "MCSD in a Nutshell" and "VB Distributed Exam Cram" - PM me for details. Will also trade for a decent ATX Pentium 2 MB/CPU/RAM combo.

  4. #4

    Thread Starter
    Frenzied Member
    Join Date
    Jan 2001
    Location
    Denmark
    Posts
    1,049
    Hi punkie_uk and JoshT!
    I have a problem which I think is easy for one of you two freaks to answer. The post is http://www.vbforums.com/showthread.p...readid=194722.
    I'm looking forward for a reply

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width