PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Tuesday, August 2, 2022

[FIXED] How to enter number of rows and columns, and create a table

 August 02, 2022     html, html-table, javascript, onclick, parameters     No comments   

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)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing