Snitz Forums 2000
Snitz Forums 2000
Home | Profile | Register | Active Topics | Members | Search | FAQ
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 Community Forums
 Code Support: ASP (Non-Forum Related)
 JavaScript parameters
 New Topic  Topic Locked
 Printer Friendly
Author Previous Topic Topic Next Topic  

Kristabel
New Member

United Kingdom
83 Posts

Posted - 18 April 2001 :  06:25:44  Show Profile  Visit Kristabel's Homepage
I'm trying to create a function that takes a table name and the name of a label so that I can delete a row from the appropriate table and hide the 'remove' label if it is the last row.

It works fine when I use the table name directly, e.g.
var newRow = myTable.deleteRow();
but when I try
var newRow = [tableName].deleteRow();
where tableName is the parameter I pass to it, I get the error 'Object doesn't support this property or method'.

Any ideas?

'Live, love and learn'

cevans
Junior Member

Canada
101 Posts

Posted - 18 April 2001 :  14:51:02  Show Profile  Send cevans an ICQ Message
If you are passing the function the table name, then the error is because the table name is a string. You are thus trying to call the deleteRow() method on a string instead of on the actual table.

You can resolve this in two ways. One is to pass the function the actual table object. The other is to get a reference to the table object inside the function (using the table name that you pass in as a parameter).


Clark
Go to Top of Page

Kristabel
New Member

United Kingdom
83 Posts

Posted - 19 April 2001 :  03:49:06  Show Profile  Visit Kristabel's Homepage
Ahh, I am passing the name as a string. I don't fully understand your suggestions for passing a reference to the table object.

Could you give me any help on how to do that please?

'Live, love and learn'
Go to Top of Page

cevans
Junior Member

Canada
101 Posts

Posted - 19 April 2001 :  08:36:58  Show Profile  Send cevans an ICQ Message
Sure, no problem. It really depends on where you're calling your function from, though. These examples should get you started, but if you need more help post some sample code or email it to me and I'll take a look at it.

This passes a reference to the table into the function. Note that written this way, it works in IE browsers only. I've generated the reference to the table a couple different ways each time, to show that there is more than one way to do it.

<script language="JavaScript">
function Foo(theTable) {
alert(theTable.id);
//you could call theTable.deleteRow() here
}
</script>
<input type="button" value="Click Me" onclick="JavaScript:Foo(document.all.someTableName)">
<table id="someTableName">
<tr id="someTableRow">
<td><input type="button" value="Click Me" onclick="JavaScript:Foo(this.parentNode.parentNode.parentNode.parentNode)">
<td><input type="button" value="Click Me" onclick="JavaScript:Foo(document.all.someTableName)">
</tr>
<tr onmouseover="JavaScript:Foo(this.parentNode.parentNode)">
<td>Hover over me</td>
</tr>
<tr onmouseover="JavaScript:Foo(document.all('someTableName'))">
<td>Hover over me, too</td>
</tr>
</table>


Personally, though, I would opt to pass the name of the table into the function, and get a reference to the table object using it. It's simpler, cleaner, easier to read, and can quite easily be made to be browser-independent. I've left the non-IE browser code out for simplicity, however.

<script language="JavaScript">
function Foo2(theTableName) {
var theTable;
if ( document.all ) {
//IE browser
theTable = document.all(theTableName);
alert(theTable.id);
} else {
//non-IE browser
//add code in here to get reference to table
theTable = "";
}
//you could then call theTable.deleteRow() here
}
</script>
<input type="button" value="Click Me" onclick="JavaScript:Foo2('someOtherTableName')">
<table id="someOtherTableName">
<tr id="someTableRow">
<td><input type="button" value="Click Me" onclick="JavaScript:Foo2('someOtherTableName')">
</tr>
<tr onmouseover="JavaScript:Foo2('someOtherTableName')">
<td>Hover over me</td>
</tr>
</table>


Clark
Go to Top of Page

Kristabel
New Member

United Kingdom
83 Posts

Posted - 19 April 2001 :  08:41:55  Show Profile  Visit Kristabel's Homepage
Thanks! This code looks great

I will give it a go this afternoon and let you know how it goes. Luckily I don't have to worry about anything but IE because I'm working on an IE-only back-end publishing system.



'Live, love and learn'
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Topic Locked
 Printer Friendly
Jump To:
Snitz Forums 2000 © 2000-2021 Snitz™ Communications Go To Top Of Page
This page was generated in 0.38 seconds. Powered By: Snitz Forums 2000 Version 3.4.07