Issue
I'm still taking HTML lessons, but I managed to do this last week and now I've completely forgotten the answer.
Basically there are two inputs. In one, you enter the number of columns, and the other, the number of rows. When you press a button it creates a table with those in mind (contents of the table don't matter). I'm supposed to use parameters in a function but I forgot a little how they work, and this is the mess that I ended up with: I'm pretty sure that everything excluding the parameters part is right. I just don't know how to get the values from the input texts and use them as parameters.
<html>
<head> <title> Rows and Columns </title> </head>
<body>
<form name="form">
Number of rows: <input type="text" name="row" />
Number of columns: <input type="text" name="col" />
<input type="button" onClick="create(c,r)" value="create" />
</form>
<script>
function create(c,r) {
c=document.forms.form.col.value
r=document.forms.form.row.value
document.write("<table width='1'>" +
for(i=1;i<=r;i++) { document.write("<tr>" +
for(e=1;e<=c;e++) { document.write("<td>" + c + "</td>") } + "</tr>") } + "</table>")
</script>
</body>
</html>
Solution
You can pass values when you are calling the onClick like this:
<input type="button" onClick="create(document.forms.form.col.value, document.forms.form.row.value)" value="create" />
remove these from create function
c=document.forms.form.col.value
r=document.forms.form.row.value
Answered By - Garry Answer Checked By - Robin (PHPFixing Admin)
0 Comments:
Post a Comment
Note: Only a member of this blog may post a comment.