Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Table Editing

Status
Not open for further replies.

Sheltered

Programmer
Nov 26, 2002
55
GB
Hi there, this is my first posting on here as im a newb in th js world.
Anyway i need some, well maybe a lot, of help.
I need to make a page which contains basically a table. The purpose of the table is simply to display information for other users to see. But i need users to be able to add to the table from the webpage (using a form). i.e. they fill in a form and click 'submit'. the js then adds a new row to the bottom of the table and fills in the details submitted. This is then saved in the table and will be displayed each time the page is loaded.
I've searched the forum and came across this thread javascript:eek:penindex(450,350,'which i thought would set me on my way but i'm having troubles. I have updated some of the code to my requirements but now i'm stuck.
Firstly, i cant get it to write more than one row at a time, it just overwrites what it originally wrote. and secondly it doesnt save so every time i refresh the page i lose the details i added.
I'll post the page with script etc so you can see what i've done. Oh and the alerts in the script are just to help me debug so i knew what was working they wont be there in the end :)
Also i'm aware this would probably be easier done with asp but it must be done with html and js as i'm not able to use asp or databases.
Like i say i'm new to js so its probably something simple that i'm not aware of.
Hope all of that was clear.
Any help would be much appreciated.
Thanks

Pete

Heres what i've got so far:
<!DOCTYPE html
PUBLIC &quot;-//W3C//DTD XHTML 1.0 Transitional//EN&quot;
&quot;

<html>
<head>
<title> Table </title>
<script language=&quot;JavaScript&quot;>
function addRow() {
var oRow;
var oCell1;
var oCell2;
var newnumber;


newnumber = dynatable.rows.length;
oRow = dynatable.insertRow();
oCell1 = oRow.insertCell();
oCell1.innerHTML = &quot;<input type='text' name='item&quot; + newnumber + &quot;'>&quot;;
oCell2 = oRow.insertCell();
oCell2.innerHTML = &quot;<input name='notes&quot; + newnumber + &quot;' type='text' size='75'>&quot;;
form1.numberRows.value++;
}

function test() {
var rows;
rows = form1.numberRows.value
alert(rows)
for (i=1; i<=rows; i++) {
var string='form1.item'+i+'.value';
var string2='form1.notes'+i+'.value';
alert(string + ' ' + string2)
document.all.daOne.innerHTML = '<table border=&quot;1&quot;><tr><td style=&quot;text-align:center&quot;>'+string+'</td><td style=&quot;text-align:center&quot;>'+string2+'</td></tr></table>'
}
}
</script>
</head>
<body>
<form name=&quot;form1&quot; method=&quot;POST&quot; action=&quot;table.html&quot;>
<input type=&quot;button&quot; name=&quot;Button&quot; value=&quot;Add Row&quot; onClick=&quot;addRow()&quot;>
<table border=&quot;1&quot; id=&quot;dynatable&quot;>
<thead>
<tr bgcolor=&quot;powderblue&quot;>
<td><strong>Date</strong></td>
<td><strong>Notes</strong></td>
</tr>
</thead>
<tbody id=&quot;TheBody&quot;>
<tr>
<td><input type=&quot;text&quot; name=&quot;item1&quot;></td>
<td><input name=&quot;notes1&quot; type=&quot;text&quot; size=&quot;75&quot;></td>
</tr>
</tbody>
</table>
<input type=&quot;button&quot; name=&quot;Submit&quot; value=&quot;Add Item(s)&quot; onClick=&quot;test()&quot;>
<input type=&quot;hidden&quot; name=&quot;MM_insert&quot; value=&quot;form1&quot;>
<input name=&quot;numberRows&quot; type=&quot;hidden&quot; id=&quot;numberRows&quot; value=&quot;1&quot;>
</form>
<hr />

<span id=daOne style=&quot;position:relative&quot;> </span>

</body>
</html>
 
hi Sheltered,

where do you intend on storing this table's data? typically you would store such data in a database, then use server-side script (asp, jsp, php...) to retrieve & save new data.

=========================================================
if (!succeed) try();
-jeff
 
I thought the data could be stored in either a seperate html page containing just the table or possibly a table on the same page? is that not possible?

thanks
Pete
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top