Click to See Complete Forum and Search --> : unsolved problem...please help me!


mili
05-05-2003, 07:43 PM
I've been unsucessful in solving this problem for several days.Khalid gave me an example for this, but unfortunately that's not exactly what I wanted.Please can some one help me?
I'm trying to delete rows that have been checked using javascript.This is simple.However, my table rows are dynamically generated using JS and how would I know which of these boxes were checked and how can I delete these rows?Here is my code:
<html>
<html>
<head>
<script language="JavaScript" type="text/javascript">
function addRow(id){
var tbody = document.getElementById
(id).getElementsByTagName("TBODY")[0];
var row = document.createElement("TR")
var td1 = document.createElement("TD")
td1.innerHTML = "<input type=checkbox align=center name='"+name+"' id='"+name+"'>";
var td2 = document.createElement("TD")
td2.innerHTML = "<span class=sub-title>Class Name : </span><select size=1 name='"+name+"' id='"+name+"'><option selected>Select an option<option value=1>option 1<option value=2>option 2<option value=3>option 3</select>";

var td3 = document.createElement("TD")
td3.innerHTML = "<input type=text align=center size=25 name='"+name+"' id='"+name+"'>";

var td4 = document.createElement("TD")
td4.innerHTML = "<input type=text align=center size=25 name='"+name+"' id='"+name+"'>";

row.appendChild(td1);
row.appendChild(td2);
row.appendChild(td3);
row.appendChild(td4);
tbody.appendChild(row);

}
</script>
</head>
<body>
<form name="Test">
<table id="myTable" cellspacing="0" width="100%" border="1">
<tbody>
<tr bgcolor="#cfcfcf">
<td width="10%"><input type="button" value="Delete"><input type="button" value="Add Row" onclick="addRow('myTable')"></td>
<td width="30%">column1</td>
<td width="30%">column2</td>
<td width="30%">column3</td>
</tr>

</tbody>
</table>
</form>
</body>
</html>

Jona
05-05-2003, 09:16 PM
Declare your variables before you function so that they will be accessible for the next function (delete).

Jona
05-05-2003, 09:40 PM
Okay, here is a function that works, but it deletes the row as soon as it's made. My problem is, if I don't call the deleteRow function with the addRow() function, the variables return undefined..

mili
05-05-2003, 10:25 PM
Jona,

Firstly, Thanks for your time.
deleterow() function deeletes rows from last.I'm trying to delete only the checked rows and I cant figure out how to go about doing it.

Jona
05-05-2003, 10:28 PM
OK, you figure out how to get the deleteRow() function to work right. I mean, try to figure out how to make the deleteRow() function able to be called from anywhere (onClick of the delete button, for example). I got it to call from the addRow() function, but first we have to figure out how to get it to work from any event.. That will take work. The checkbox part can come later. Get what I mean? ;)

mili
05-05-2003, 11:02 PM
Sounds good to me :)

I'm getting deleterow to work now.

mili
05-05-2003, 11:21 PM
I cant stay awake.I will be back tomorrow.See you around tomorrow :)
Good night

Jona
05-05-2003, 11:27 PM
Okay. Whenever you've got it, just post. :) Seeya.

mili
05-06-2003, 06:48 AM
Alright, I've attached the code. Delete function works.
Here it is :)

Jona
05-06-2003, 11:19 PM
OK, your delete function worked, but I made it to work in Netscape 6+ and not cause errors in NN4 (at least, that's what I hope the code did). Also, your code had one little bug that I fixed. Your code lets you delete the row with the buttons if there are no other rows! (Try your code. Just click the "Delete row" button before any other button, you'll see what I mean.) I fixed it. See http://geocities.com/god_loves_07/add_del_tbl.html

Jona
05-06-2003, 11:56 PM
I updated the code again. And I'm not 100% sure it works in NS6, but it works in IE6. Anyways, the code now deletes all rows that come AFTER the box that is checked. I know it's not what we want, but it's a start, right? ;)

Seeya later..

mili
05-07-2003, 10:33 AM
Originally posted by Jona
OK, your delete function worked, but I made it to work in Netscape 6+ and not cause errors in NN4 (at least, that's what I hope the code did). Also, your code had one little bug that I fixed. Your code lets you delete the row with the buttons if there are no other rows! (Try your code. Just click the "Delete row" button before any other button, you'll see what I mean.) I fixed it. See http://geocities.com/god_loves_07/add_del_tbl.html



You are right about that.I overlooked that problem.Thanks for fixing.
Also, I dont need this to be netscape compatible.This reduces a lot of burden :)

Jona
05-07-2003, 10:53 AM
Cool. Well, I was thinking it would be better to make it Netscape compatible anyways. ;) I mean, after all, there are a lot of people who use Netscape (khaki LOL), and I don't want to "include them out." :p So if it's DOM-compatible, I'm gonna try to get it to work... But until I get my new hard drive... I can't debug with Netscape.

I was dreaming last night (no, I don't actually do that every night), and I dreamed how to get it to work.... I think... I'll go work on it some more. Ta ta for now! :)

Jona
05-07-2003, 11:22 AM
By the way, how did you figure out the deleteRow() method? Do you know of a site that lists all possible methods/properties of a table? If so, please give me a link!

Also, I couldn't quite figure out how to delete the checked ones. I'm getting close, but if I knew what properties and methods a table normally has, I could probably figure it out then.... I'll try MSDN.

Jona
05-07-2003, 11:47 AM
OK, I found it: http://msdn.microsoft.com/library/default.asp?url=/workshop/author/html/reference/elements.asp

In the TR and the TABLE reference. There is instertRow() and deleteRow(). I'll work on it some more... But I think my for() loop froze the browser a second ago. :eek: LOL...

mili
05-07-2003, 07:32 PM
Jona, I really appreciate your help. Thanks a lot.Now, I'm trying to write a function to gather all the values that have been entered so that I can store them in input hidden fields and pass the values thro form's post.I hope I can do it :)

Jona
05-07-2003, 07:34 PM
It's no problem at all. Khalid and AdamBrill are helping me out a little.. I wanted to use the funciton a certain way, but it looks like I might have to do it different to what I wanted.