[jQuery] Re: getting the ID number of a cloned table row

2008-02-05 Thread Charles K. Clarkson

Bruce MacKay wrote:
: Hello folks,
: 
: I'm trying to duplicate a row of an existing table using a function
: adapted from
: http://www.nabble.com/Add-Table-row-to12989886s27240.html#a13300133  
: 
: My problem is that I cannot identify the identifier of the last row
: (of the original table).

From the html you provided, this gets the last ID. 

// The match should return an array with the current id in the 0
// position. The + sign in front converts this ID to a number.
var currentID = + $(clonedRow).find('input').attr('id').match( /\d+/
)[0];
var newID = currentID + 1;

The problem is that clone() does not work right in Internet Exploder.
There's a patch due, but no advance yet. So, the solution works on FF,
but not on IE. (http://www.fusioncube.net/?p=196)

In fact, the method above needs filter() to work on IE.

// Solution for IE.
var currentID = + $(clonedRow).filter('input').attr('id').match( /\d+/
)[0];
var newID = currentID + 1;


: function duplicateRow(){
[snip]


Manipulating the html directly probably isn't the most jQuery-ish
way to handle this.

$(clonedRow).find( '#bc' + currentID ).eq(0).attr({
id: 'bc'  + newID,
name: 'correctans' + newID
});

$(clonedRow).find( '#theans' + currentID ).eq(0).attr({
id: 'theans'  + newID,
name: 'answer' + newID
});

$(clonedRow).find( '#fb' + currentID ).eq(0).attr({
id: 'fb'  + newID,
name: 'feedback' + newID
});

// Add to the new row to the original table
$( #myTable).append( clonedRow );





So, for now, you may need another solution besides clone().


HTH,

Charles K. Clarkson
-- 
Mobile Homes Specialist
Free Market Advocate
Web Programmer

254 968-8328

http://www.clarksonenergyhomes.com/wordpress/about/



[jQuery] Re: getting the ID number of a cloned table row

2008-02-05 Thread Bruce MacKay


Thanks Charles for this full and complete response - I very much appreciate it.

Cheers

Bruce

At 09:27 a.m. 6/02/2008, you wrote:


Bruce MacKay wrote:
: Hello folks,
:
: I'm trying to duplicate a row of an existing table using a function
: adapted from
: http://www.nabble.com/Add-Table-row-to12989886s27240.html#a13300133
:
: My problem is that I cannot identify the identifier of the last row
: (of the original table).

From the html you provided, this gets the last ID.

// The match should return an array with the current id in the 0
// position. The + sign in front converts this ID to a number.
var currentID = + $(clonedRow).find('input').attr('id').match( /\d+/
)[0];
var newID = currentID + 1;

The problem is that clone() does not work right in Internet Exploder.
There's a patch due, but no advance yet. So, the solution works on FF,
but not on IE. (http://www.fusioncube.net/?p=196)

In fact, the method above needs filter() to work on IE.

// Solution for IE.
var currentID = + $(clonedRow).filter('input').attr('id').match( /\d+/
)[0];
var newID = currentID + 1;


: function duplicateRow(){
[snip]


Manipulating the html directly probably isn't the most jQuery-ish
way to handle this.

$(clonedRow).find( '#bc' + currentID ).eq(0).attr({
id: 'bc'  + newID,
name: 'correctans' + newID
});

$(clonedRow).find( '#theans' + currentID ).eq(0).attr({
id: 'theans'  + newID,
name: 'answer' + newID
});

$(clonedRow).find( '#fb' + currentID ).eq(0).attr({
id: 'fb'  + newID,
name: 'feedback' + newID
});

// Add to the new row to the original table
$( #myTable).append( clonedRow );





So, for now, you may need another solution besides clone().


HTH,

Charles K. Clarkson
--
Mobile Homes Specialist
Free Market Advocate
Web Programmer

254 968-8328

http://www.clarksonenergyhomes.com/wordpress/about/




[jQuery] Re: getting the ID number of a cloned table row

2008-02-04 Thread andrea varnier

On 4 Feb, 12:51, Bruce MacKay [EMAIL PROTECTED] wrote:
 The function I'm using is as follows.  Two questions:
 1. I get an error at the alert - intCurrentRowID is not
 defined.  What is my error here?

ParseInt() returns an integer if the number is at the beginning of the
string, and undefined otherwise.
You should use substr(-1,1) to get the last character of a string.