JustinC474
07-27-2009, 06:05 PM
Well i just got booted off the server after writing an essay here so this is the short version
-Ive never worked html php or javascript, so any help, tips, etc is appreciated.
-Im making a database for some1 to store client information on and they want it to be client-side
-Each row represents 1 client
-Made a working php version, now trying to make a working JS version
heres the PHP version that prints the table correctly:
($data = 2D array of all information, $columns = array of column headers, $numRows = number of rows/clients)
function printTable()
{
echo '<table class = "halloween" border = "1">';
echo '<tr>';
foreach($this->columns as $header => $order)
{
echo '<th>';
echo $header;
echo '</th>';
}
for($i = 0; $i < $this->numRows; $i++)
{
echo '<tr>';
foreach($this->data[$i] as $value)
{
echo '<td>';
if(!$value=="")
echo $value;
else
echo '<input type = "text" size = 10>';
echo '</td>';
}
echo '</tr>';
}
echo '</table>';
}
that works!!
now i am trying to pass this information to JS file so it will be client side
I started by trying to pass the array of column headers, heres what i got
function printJSTable()
{
echo '<script src = "java_script.js">';
echo 'var js_Array = new Array();\n';
foreach($this->columns as $header => $order)
{
echo 'js_Array.push($header);\n';
}
echo '</script>';
echo '<input type = "button" value ="click" onclick = drawTable("js_Array")';
}
and here is what drawTable() currently is
function drawTable(columns)
{
alert("Hello World");
for(i=0; i<columns.length; i++)
{
alert(columns[i]);
}
}
When the button "click" is clicked it alerts "Hello World" and then alerts "j" then "s" then "_"
well it alerts letter by letter the name of the array
any tips? even tips addressing different issues would be greatly appreciated, any help at all really, even big picture stuff
thanks!
-Ive never worked html php or javascript, so any help, tips, etc is appreciated.
-Im making a database for some1 to store client information on and they want it to be client-side
-Each row represents 1 client
-Made a working php version, now trying to make a working JS version
heres the PHP version that prints the table correctly:
($data = 2D array of all information, $columns = array of column headers, $numRows = number of rows/clients)
function printTable()
{
echo '<table class = "halloween" border = "1">';
echo '<tr>';
foreach($this->columns as $header => $order)
{
echo '<th>';
echo $header;
echo '</th>';
}
for($i = 0; $i < $this->numRows; $i++)
{
echo '<tr>';
foreach($this->data[$i] as $value)
{
echo '<td>';
if(!$value=="")
echo $value;
else
echo '<input type = "text" size = 10>';
echo '</td>';
}
echo '</tr>';
}
echo '</table>';
}
that works!!
now i am trying to pass this information to JS file so it will be client side
I started by trying to pass the array of column headers, heres what i got
function printJSTable()
{
echo '<script src = "java_script.js">';
echo 'var js_Array = new Array();\n';
foreach($this->columns as $header => $order)
{
echo 'js_Array.push($header);\n';
}
echo '</script>';
echo '<input type = "button" value ="click" onclick = drawTable("js_Array")';
}
and here is what drawTable() currently is
function drawTable(columns)
{
alert("Hello World");
for(i=0; i<columns.length; i++)
{
alert(columns[i]);
}
}
When the button "click" is clicked it alerts "Hello World" and then alerts "j" then "s" then "_"
well it alerts letter by letter the name of the array
any tips? even tips addressing different issues would be greatly appreciated, any help at all really, even big picture stuff
thanks!