I have the following problem in my jscript program..My programm has the following structure: <html> <head> <title></title> <script type="text/javascript"> var result; function func(add) { result=add+5; return result; } <script> </head> <form action="#" onsubmit="func(this.add.value); return false"> <p> <input type="text" size="60" name="add"/> <input type="submit" value="Go!" /> </p> </form> </body> </html> My problem is that I want to create a table with "result" values. The variable result is being returned as you see when I press the button "Go!" and is calculated in the "func" function. How Can I create this table in the <body> </body> section without knowing the value of the "result" variable ??? For example: I write in the textbox the number 4.Then I press the button Go! Then the function func calculates the result variable and give it the value 4+5=9. (result=add+5).My problem here is that I dont know how to create a table with length = 9..I know how to create generally a table in html language but I dont know how to create it in the <body> </body> section and with a special number as result.. Please help me if you know how.. Thank you for your time and I wish u happy new year!!!
Not sure i got you idea, but hope this code helps <html> <head> <title></title> <script type="text/javascript"> var result; function func(add) { result=add+5; return result; } function createTable(val) { var result = func(val); var tableContent = "<TABLE border=1>"; for(i=0; i < result; i++) { tableContent +="<TR><TD>" + i + "</TD></TR>"; } tableContent +="</TABLE>"; var tabDiv = document.getElementById("placeForTable"); tabDiv.innerHTML = tableContent; } </script> </head> <form action="#" onsubmit="createTable(this.add.value); return false"> <p> <input type="text" size="60" name="add"/> <input type="submit" value="Go!" /> </p> </form> </body> <div id="placeForTable"> </div> </html>