Javascript-форум (https://javascript.ru/forum/)
-   Общие вопросы Javascript (https://javascript.ru/forum/misc/)
-   -   Формирование массива. Работа с данными. (https://javascript.ru/forum/misc/36132-formirovanie-massiva-rabota-s-dannymi.html)

mynameIsMax 04.03.2013 22:55

Формирование массива. Работа с данными.
 
Всем здравствуйте. Возникла проблема с формированием массива. В массив вносятся данные о человеке: имя, фамилия и отчество, к примеру создаем список из трех людей. В итоге получаем массив и выводим данные в таблицу. Но в конце концов когда я хочу вытянуть из массива данные о человеке всегда вытягивается последний. Почему? Что я пропустил или неправилиьно передаю данные? Скрипт приведен ниже:

<!DOCTYPE html>
<html>
 <head>
  <meta charset="utf-8">
  <title></title>
<script> 
var arr=new Array();
function createVisitCard(){
	var newWindow;
	newWindow = window.open('','','toolbar=no, scrollbars=no, left=10, top=10, width=300, height=150');
	newWindow.document.open("text/html", "replace");
	newWindow.document.write("<p>"+document.frm.name.value+"</p>");
	newWindow.document.write("<p>"+document.frm.position.value+"</p>");
	newWindow.document.write("<p>"+document.frm.phone.value+"</p>");
	newWindow.document.write("<p>"+document.frm.something.value+"</p>");
	newWindow.document.write("<p>"+document.frm.list.value+"</p>");
	newWindow.document.close();
	}
function createTable(n,s,p,x){ 

    document.write('<tr>');
    document.write('<td > ' + n + ' </td> <td > ' + s + '</td> <td > ' + p + ' </td><td><form ><input type="button" value="Открыть в новом окне" onClick="getbyID('+x+')"/></form></td>');
    document.write('</tr>');

    }       
function getbyID(id){
	var newWindow;
	newWindow = window.open('','','toolbar=no, scrollbars=no, left=10, top=10, width=300, height=150');
	newWindow.document.open("text/html", "replace");
	newWindow.document.write('<table width="100%" align="center">');
	newWindow.document.write('<tr>');
	newWindow.document.write('<td > ' + arr[id,0] + ' </td> <td > ' + arr[id,1] + '</td> <td > ' + arr[id,2] + ' </td>');
	newWindow.document.write('<tr>');
	newWindow.document.write('</table>');
	newWindow.document.close();}
function getArr(){
var newWindow;
	newWindow = window.open('','','toolbar=no, scrollbars=no, left=10, top=10, width=300, height=150');
	newWindow.document.open("text/html", "replace");
newWindow.document.write('<table');
for (var z=0;z<3;++z){
	newWindow.document.write('<tr>');
	for(var a=0;a<3;++a)
	newWindow.document.write('<td > '+arr[z,a]+'</td > ');	
	newWindow.document.write('</tr>');}
	newWindow.document.write('</table >');
	newWindow.document.close();}

</script>
 </head>
 <body>
 <table >

<tr>
<td>
<input type="button" value="Create Visit Card" onClick="createVisitCard()"/>
</td>
</form>
</tr>
</table>
<script>
document.write('<table width="100%" align="center">');
for (var i=0;i<3;++i)
{var name = prompt('Введите имя:');
 var surname = prompt('Введите фамилию:');
 var patronymic = prompt('Введите отчество:');
 arr[i]=new Array();
 arr[i,0]=name;
 arr[i,1]=surname;
 arr[i,2]=patronymic;
 createTable(arr[i,0],arr[i,1],arr[i,2],i);  
 }
 document.write('</table>');
</script>
<form ><input type="button" value="Вывести массив" onClick="getArr()"/></form>
 </body>
</html>

danik.js 05.03.2013 05:00

Цитата:

Сообщение от mynameIsMax
arr[i,0]

Что это значит? Правильно arr[0], arr[1] и тд. Никаких запятых.

mynameIsMax 05.03.2013 11:07

Цитата:

Сообщение от danik.js (Сообщение 238805)
Что это значит? Правильно arr[0], arr[1] и тд. Никаких запятых.

Браво кэп? Что дальше? Я пробовал и с запятыми и без, результат одинаковый

danik.js 05.03.2013 11:19

Цитата:

Сообщение от mynameIsMax
Браво кэп?

Если ты городишь такую поеботину, то врядли для тебя это очевидно, малыш. Теперь приведи нормальный код, если ждешь помощи.


Часовой пояс GMT +3, время: 15:13.