/    Sign up×
Community /Pin to ProfileBookmark

Table listing using javascript – not working :(

I have this sample code, it should make lister under html table. But only first click is working then there is error crateTable not defined… Could you please help me?

Many thanks

—— lister.js ——-

function createTable(page) /* {{{ */
{
// prepare some variables
var onpage = 10;
var from = onpage * (page – 1) + 1;
var to = from + onpage – 1 ;

// prepare input array
input =
[
[12345, “Mercedes”, “Světoznámé auto světoznámého výrobce”],
[43545, “Škoda”, “Popis Škoda….”],
[12342, “Trabant”, “Popis trabantu”],
[53423, “Audi”, “Audi Audi Audi Audi”],
[76746, “Tatra”, “Popis Tatra”],
[45776, “Peugeot”, “Popis Peugeot..”],
[23452, “Volvo”, “Volvo Volvo Volvo Volvo Volvo”],
[89423, “Citroen”, “Co nového u citroenu”],
[39832, “Velorex”, “Velorex cabrio”],
[48754, “Chevrolet”, “Popis Chevrolet”],
[73432, “Ferrari”, “Ferrari Ferrari Ferrari”],
[36723, “Lotus”, “Popis u Lotusu”],
[63445, “Porsche”, “Popis Porschete”],
[32523, “UAZ”, “Slavný vůz”],
[32513, “UAZ2”, “Slavný vůz”],
[32503, “UAZ3”, “Slavný vůz”],
[32513, “UAZ3”, “Slavný vůz”],
[32523, “UAZ3”, “Slavný vůz”],
[32533, “UAZ3”, “Slavný vůz”],
[32543, “UAZ3”, “Slavný vůz”],
[32553, “UAZ3”, “Slavný vůz”],
[32563, “UAZ3”, “Slavný vůz”],
[32573, “UAZ3”, “Slavný vůz”],
[32583, “UAZ3”, “Slavný vůz”]
];

// just tu make it shorter
il = input.length;

// write table
output = ‘<table border=1>’;

for( var i=from; i<=(to>il?il:to); i++ )
{
output += ‘<tr>’;
output += ‘<td>’ + i + ‘</td>’;
output += ‘<td>’ + input[i][0] + ‘</td>’;
output += ‘<td>’ + input[i][1] + ‘</td>’;
output += ‘<td>’ + input[i][2] + ‘</td>’;
output += ‘</tr>’;
}
output +='</table>’;

// write lister left
if(page>1)
{
output += ‘<a href=”javascript:createTable(‘+(page-1)+’);return true;”>&lt;&lt;</a> – ‘;
}
else
{
output += ‘&lt;&lt; – ‘;
}

// lister numbers
for (i=1; i<=(il/onpage)+(il%onpage==0?0:1);i++)
{
if(i==page)
{
output += i + ‘ – ‘;
}
else
{
output += ‘<a href=”javascript:createTable(‘+i+’)”>’+i+'</a> – ‘;
}
}

// lister right
if((page*onpage)<il)
{
output += ‘<a href=”javascript:createTable(‘+(++page)+’);”>&gt;&gt;</a>’;
}
else
{
output += ‘&gt;&gt;’;
}

// yeah, give it to me 😉
document.write(output);

}

—— table.html ——
<html>
<head>
<meta http-equiv=”Content-Type” content=”text/html; charset=windows-1250″>
<script language=”JavaScript” src=”list.js”></script>
</head>
<body>
<script language=”JavaScript”>
createTable(1);
</script>
</body>
</html>

to post a comment
JavaScript

1 Comments(s)

Copy linkTweet thisAlerts:
@KorJul 28.2005 — Better use DOM methods to create a table.

See some examples at

http://www.webdeveloper.com/forum/showthread.php?t=74055
×

Success!

Help @beko spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.4,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,

tipper: @Samric24,
tipped: article
amount: 1000 SATS,
)...