There are problems with writing a script that displays a table with the names of people, the year of birth is a random number 1900 - 2016, and a weight of 3 is 150.

It is necessary that the table be displayed on a separate tab of the browser . It is necessary that there was a function that builds the table, and then when creating window.open () this function was called? I understand, it will sound brazenly, but correct my code.

<html> <head> <meta charset = "windows - 1251"> <title>Таблица имен</title> <style> table { width: 50%; border: 3px solid black; border-collapse: collapse; margin: auto; } td, th { padding: 2px; border: solid black; } th { background: deepskyblue; } .center { text-align: center; } tbody tr:hover { background: cyan; } </style> </head> <body> <script> function randomValue(min, max) { return Math.floor(Math.random() * (max - min + 1) + min); } amount = +prompt("Введите количество полей:"); document.write ('<p align = "center" style = "font-size: 30px">Таблица персональных даних</p>'); document.write ('<table>'); document.writeln('<tr> <th>№<\/th><th>Ф.И.О.<\/th><th>Год рождения<\/th><th>Вес<\/th> <\/tr>'); for (var i = 0; i < amount; i++) { var name = prompt("Введите Ф.И.О." + (i + 1) +" - го человека"); if (name.trim() == ""){ do { name = prompt("Вы ничего не ввели. Попробуйте еще раз:") } while (name.trim() == "");} document.writeln('<tr class = "center">'); document.writeln('<td>' + (i + 1) + '<\/td>'); document.writeln('<td>' + name + '<\/td>'); document.writeln('<td>' + randomValue(1900, 2016) + '<\/td>'); document.writeln('<td>' + randomValue(3, 150) + '<\/td>'); document.writeln('<\/tr>'); } document.write ('</table>'); </script> </body> </html> 
  • but where does the data come from? - Vasily Barbashev
  • What is the question? - Grundy
  • What data? Do you mean names and number of lines? They after all are entered through prompt. And I asked for help in editing the code - Muscled Boy
  • and what is necessary to edit? What is the problem I can not understand - no one can :-) you did not write what problem you see in your code - Grundy
  • I don't know, it just doesn't work - Muscled Boy

1 answer 1

Something like this you need?

 <script> function randomValue(min, max) { return Math.floor(Math.random() * (max - min + 1) + min); } amount = +prompt("Введите количество полей:"); var wnd = window.open('#','_blank'); wnd.document.write ('<html>'); wnd.document.write ('<head>'); wnd.document.write ('<title></title>'); wnd.document.write ('<link rel="stylesheet" type="text/css" href="tablestyle.css">'); wnd.document.write ('</head>'); wnd.document.write ('<body>'); wnd.document.write ('<p align = "center" style = "font-size: 30px">Таблица персональных даних</p>'); wnd.document.write ('<table>'); wnd.document.writeln('<tr> <th>№<\/th><th>Ф.И.О.<\/th><th>Год рождения<\/th><th>Вес<\/th> <\/tr>'); for (var i = 0; i < amount; i++) { var name = prompt("Введите Ф.И.О." + (i + 1) +" - го человека"); if (name.trim() == ""){ do { name = prompt("Вы ничего не ввели. Попробуйте еще раз:") } while (name.trim() == "");} wnd.document.writeln('<tr class = "center">'); wnd.document.writeln('<td>' + (i + 1) + '<\/td>'); wnd.document.writeln('<td>' + name + '<\/td>'); wnd.document.writeln('<td>' + randomValue(1900, 2016) + '<\/td>'); wnd.document.writeln('<td>' + randomValue(3, 150) + '<\/td>'); wnd.document.writeln('<\/tr>'); } wnd.document.write ('</table>'); wnd.document.write ('</body>'); wnd.document.write ('</html>'); </script> 
  • Comments are not intended for extended discussion; conversation moved to chat . - Nick Volynkin