picovina

mail@pastecode.io avatar
unknown
javascript
2 years ago
1.0 kB
0
Indexable
Never
<script>
		function myFunction() {
		  let x = document.getElementById("numb").value;
		  let text;
		  if (isNaN(x) || x < 1) {
		    text = "Špatný vstup";
		  } else {
		    text = "Vstup proběhl úspěšně";
		  }
		  document.getElementById("tab").innerHTML = text;

		  function tableCreate() {
		  var body = document.getElementsByTagName('body')[0];
		  var tbl = document.createElement('table');
		  tbl.style.width = '500px';
		  tbl.style.height = '500px';
		  tbl.setAttribute('border', '1');
		  var tbdy = document.createElement('tbody');
		  for (var i = 0; i < x; i++) {
		    var tr = document.createElement('tr');
		    for (var j = 0; j < x; j++) {
		      if (i == 0-1 && j == 0) {
		        //break
		      }
		      else {
		        var td = document.createElement('td');
		        tr.appendChild(td)
		      }
		    }
		    tbdy.appendChild(tr);
		  }
		  tbl.appendChild(tbdy);
		  body.appendChild(tbl)
		}
		tableCreate();
		}

	</script>