» Site Navigation | | | » Advertisement | | | » Recent Threads | | | | | [PC]Account Today 07:11 AM Today 07:11 AM 0 Replies, 1 Views | | | | | |  |  | [javascript]need some help |  |
07-01-2008, 09:55 PM
|
#1 (permalink)
| | Underground
revolution is offline
Join Date: Aug 2007 Location: Hiram, Georgia Age: 19 Posts: 557 Rep Power: 4 | [javascript]need some help I'm looking for a pretty simple code. I can find codes to do the separate parts, but I can't manage to combine them to do what I need.
Contains the following:
1. A table
2. A textbox
3. Two buttons
What I want to be able to do is type something in the text box and click a button that says "Add Item". It then adds the input text to a cell in a row in the table and in the cell next to it, a button that says "Delete" that will delete that row, removing the item and its "Delete" button from the table. I'd like to be able to add as many items as I want.
EDIT
Also needs to be able to store the list so that you can update it later.
__________________ Trades Completed: Yummy, Kismet, Konekokoi, xRuinationx
Last edited by revolution; 07-02-2008 at 07:35 AM.
| |
| |  | |  |
07-01-2008, 11:32 PM
|
#2 (permalink)
| | Underground
dyl1828 is offline
Join Date: Feb 2007 Age: 15 Posts: 136 Rep Power: 5 | Here you go,
Example: Example Code: <html>
<head>
<title>Test Page</title>
<script type="text/javascript">
function appendRow()
{
var text= document.form.input.value;
var button= '<input type="button" value="Delete" onclick="deleteRow(this.parentNode.parentNode.rowIndex)">'
var tbody = document.getElementById("t1").getElementsByTagName("tbody")[0];
var row = document.createElement("TR");
var cell1 = document.createElement("TD");
cell1.innerHTML = text;
var cell2 = document.createElement("TD");
cell2.innerHTML = button;
row.appendChild(cell1);
row.appendChild(cell2);
tbody.appendChild(row);
}
function deleteRow(i){
document.getElementById('t1').deleteRow(i)
}
</script>
</head>
<body>
<table id="t1" border="1">
<tbody>
</tbody>
</table>
<form name="form" id="form">
<textarea id="input" name="input"></textarea>
<input onclick="appendRow()" value="Add Item" type="button">
</form>
</body>
</html> Hope you enjoy
P.S.
This code was tested and created on Firefox 2.0.0.14 with Javascript enabled
__________________
Trades Completed With Users On GG: Dungeon_Master (gaiaonline<>neopets)
Last edited by dyl1828; 07-01-2008 at 11:33 PM.
Reason: forget information
| |
| |  |
07-02-2008, 06:18 AM
|
#3 (permalink)
| | Underground
revolution is offline
Join Date: Aug 2007 Location: Hiram, Georgia Age: 19 Posts: 557 Rep Power: 4 | Exactly what I was looking for. Hadn't planned on using a textarea, but that's not a problem.
EDIT
I forgot one thing, I need it to not delete every time I refresh or go back to the page. I want it to be able to store so that every time I go back to it, the list is still there and I can sitll add items or delete the ones on there like normal.
__________________ Trades Completed: Yummy, Kismet, Konekokoi, xRuinationx
Last edited by revolution; 07-02-2008 at 06:26 AM.
| |
| |
07-02-2008, 09:34 AM
|
#4 (permalink)
| | Underground
dyl1828 is offline
Join Date: Feb 2007 Age: 15 Posts: 136 Rep Power: 5 | do you mind if it includes php in the script, because that is the only way i know how to do that.
Also without php you cant save the it because javascript is only client side (so you cant save to the server)
Edit:
Sorry, but i cant think or find a way to save the table. Sorry.
__________________
Trades Completed With Users On GG: Dungeon_Master (gaiaonline<>neopets)
Last edited by dyl1828; 07-02-2008 at 10:50 AM.
| |
| |
07-02-2008, 03:48 PM
|
#5 (permalink)
| | Underground
revolution is offline
Join Date: Aug 2007 Location: Hiram, Georgia Age: 19 Posts: 557 Rep Power: 4 | Doesn't have to be javascript, can be whatever language, use MySQL, whatever.
__________________ Trades Completed: Yummy, Kismet, Konekokoi, xRuinationx | |
| |
07-02-2008, 04:43 PM
|
#6 (permalink)
| | Banned
bug14 is offline
Join Date: Oct 2007 Location: bugmenot.com Posts: 1,532 Rep Power: 0 | You can set a cookie with javascript, but the deleted row wouldn't be permanent. | |
| |
07-02-2008, 06:15 PM
|
#7 (permalink)
| | Underground
revolution is offline
Join Date: Aug 2007 Location: Hiram, Georgia Age: 19 Posts: 557 Rep Power: 4 | Quote:
Originally Posted by bug14 You can set a cookie with javascript, but the deleted row wouldn't be permanent. | It would need to be permanent.
EDIT
nuke got it fixed
__________________ Trades Completed: Yummy, Kismet, Konekokoi, xRuinationx
Last edited by revolution; 07-06-2008 at 10:27 AM.
| |
| |  | |
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | | | | Thread Tools | | | | Display Modes | Linear Mode |
Posting Rules
| You may not post new threads You may not post replies You may not post attachments You may not edit your posts HTML code is Off | | | |