www.webdeveloper.com
Results 1 to 4 of 4

Thread: a little knowledge is dangerious

  1. #1
    Join Date
    Jun 2009
    Posts
    3

    a little knowledge is dangerious

    Can some one help me please,

    I am trying to use a javascript to create a table for user input, the number of rows in the table is controlled by the user through the input text box.

    My problem is that when the user enters the number of lines required only the url gets the addition of the number entered, this is the code I am using.
    What have I done wrong?


    <html>
    <head>
    <script type="text/javascript">

    function itemtable()

    {
    var a = document.numlines.number.value;
    document.write.("<h1>Line Item Details</h1>");
    document.write("The number is " +a+);
    document.write("<table border=2 width=100%");
    document.write("<tr>");
    document.write("<th>Item No.</th><th>1</th><th>2</th><th>3</th>");

    for (var i = 1; i <= a; i++ ) {
    document.write("<tr>");
    document.write("<td>"+i+"<td><input type=text name=item3"+i+"></td><td><input type=text name=item2"+i+"></td><td><input type=text name=item1"+i+"></td>");
    document.write("</tr>");
    }

    document.write("</table>");

    }
    </script>


    </head>
    <body>



    <form name="numlines">
    <table border="2">
    <tr>
    <td><input type="text" value="" onchange="itemtable()" name="number">Number of lines required</td>
    </tr>
    </table>
    </form>

    </body>
    </html>

    Regards

  2. #2
    Join Date
    May 2003
    Location
    Between Baltimore and DC
    Posts
    3,579
    You cna not use document.write after the page loads. You need to use innerHTML or appendChild

    Eric

  3. #3
    Join Date
    Jan 2010
    Posts
    80
    Hi bud

    You main problem was that the form was trying to submit itself so to stop it from doing that you need to change the line

    Code:
    <form name="numlines">
    to

    Code:
    <form name="numlines" onsubmit="return false">
    You have two other errors in there as well

    Code:
    document.write.("<h1>Line Item Details</h1>");
    document.write("The number is " +a+);
    they should be

    Code:
    document.write("<h1>Line Item Details</h1>");
    document.write("The number is " +a);
    Your script will work after you make these changes

    V

  4. #4
    Join Date
    Jun 2009
    Posts
    3

    Vince616

    Great, thanks works now.

    S

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles