Click to See Complete Forum and Search --> : database with javascript


crazyren
01-03-2006, 06:09 AM
thiz mi8 sound stupid but i wonder weather u can make javascript to write text to a .js .txt .any file useing array any one any ideas! cuz.. u can get iformation frm a external file useing array! like

Html File

<html>
<head>
<title>Arrays</title>
<script SRC="database.txt"></script>
</head>
<body>
<p>
<table border="0" cellpadding="2" cellspacing="1">
<tr>
<td><b>ISBN</b></td>
<td><b>Title</b></td>
<td><b>Author</b></td>
<td><b>Publisher</b></td>
<script language="JavaScript">
<!--
for( i = 0 ; i < numBooks ; i++ )
{
document.write( "<tr>" );

document.write( "<td>" + bookInfo[i][0] + "</td>" );
document.write( "<td>" + bookInfo[i][1] + "</td>" );
document.write( "<td>" + bookInfo[i][2] + "</td>" );
document.write( "<td>" + bookInfo[i][3] + "</td>" );
document.write( "</tr>" );
}
// -->
</script>
<table>
</p>
</body>
</html>

Database file

var numBooks = 5;
var bookInfo = new Array( numBooks );

bookInfo[0] = new Array( 4 );
bookInfo[0][0] = "0-201-10088-6";
bookInfo[0][1] = "<img scr=http://www.google.com/images/logo_sm.gif>";
bookInfo[0][2] = "Alfred V. Aho etc."
bookInfo[0][3] = "Addison-Wesley Publishing Company";

bookInfo[1] = new Array( 4 );
bookInfo[1][0] = "0-201-89685-0";
bookInfo[1][1] = "The Art of Computer Programming Vol.3";
bookInfo[1][2] = "Donald E. Knuth";
bookInfo[1][3] = "Addison-Wesley";

bookInfo[2] = new Array( 4 );
bookInfo[2][0] = "0-13-899394-7";
bookInfo[2][1] = "Java-How to Program";
bookInfo[2][2] = "Deitel & Deitel";
bookInfo[2][3] = "Prentice Hall";

bookInfo[3] = new Array( 4 );
bookInfo[3][0] = "0-7645-4003-3";
bookInfo[3][1] = "HTML & Web Publishing Secrets";
bookInfo[3][2] = "Jim Heid";
bookInfo[3][3] = "IDG Books Worldwide, Inc.";

bookInfo[4] = new Array( 4 );
bookInfo[4][0] = "0-13-091013-9";
bookInfo[4][1] = "Assembly Language for Intel-Based Computers";
bookInfo[4][2] = "Kip R. Irvine";
bookInfo[4][3] = "Prentice Hall";

in thiz case u can view da data frm da Database file! iz thr any way to write data to da database file! any if u know plz reply! :D thnX

crazyren
01-03-2006, 09:35 AM
anyone any idea! :confused:

Rik Comery
01-03-2006, 09:35 AM
JavaScript cannot write to a file. to do this, you need another scripting language such as ASP, PHP etc. Your example is not really the same thing. JavaScript cannot read the external file, and load only the information it needs. It actually loads the entire external file and combines it with the HTML page.

because of this, it is likely to take ages for the page to load if the external file becomes too large (As is probably the case if you want it to act as a database.)

crazyren
01-03-2006, 09:37 AM
0o. i c thnX dude!