views:

38

answers:

5

Hi, i have this problem: i need to remove the "disabled" attibute from the siblings inputs of submit input. Here is the html:

<td>
<input type="hidden" value="2000000000002_STATUTO_07_10_2010.gif" name="nomeDocumento" disabled="true">
<input type="hidden" value="811ecdd0-65e9-49d6-8d9d-8b7c9d9b6407" name="UUID" disabled="true">   
<input type="submit" value="cancella" name="cancella">
</td>

i need a simple way using jquery to remove the disable attribute when i click on the submit. I tried:

$('input[name=cancella]').click(function(){
$('this').prev().removeAttr('disabled');
$('this').prev().prev().removeAttr('disabled');
}

But i doesn't work.

Any suggestion?

+1  A: 

Ciao,

have you tried .prevAll() ?

$('input[name=cancella]').click(function(){
  $(this).prevAll().removeAttr('disabled');
}

http://api.jquery.com/prevAll/

Note: this is an object, not a string literal (you wrote 'this')

Fabrizio Calderan
+1 for noticing 'this' and using .prevAll()
BGerrissen
+2  A: 
$('input[name=cancella]').click(function(){
   $(this)
      .closest('td')
      .find('input[name!='+this.name+']')
      .attr('disabled', false);
});

Fabrizio Calderan .prevAll() way is better. However, .siblings() could be even better, so it doesn't matter where the siblings are.

$('input[name=cancella]').click(function(){
   $(this).siblings('input').attr('disabled', false);
});

Using .attr('disabled', false) should work as well and could be more reliable.

BGerrissen
thanks to all of you, the main error was in the use of $('this') instead of $(this). I'll keep this thing in mind from now on! :)
Nicola Peluchetti
A: 

Simply remove quotes around this i.e.

$('input[name=cancella]').click(function(){
    $(this).prev().removeAttr('disabled');
    $(this).prev().prev().removeAttr('disabled');
}

this is your object not value for attribute [name/id]

Chinmayee
A: 

You can use the .siblings() traversing method:

$('input[name=cancella]').siblings().removeAttr('disabled');

Have a look at this link JQuery Sibling

dmarucco
And also, like others noticed, you must write $(this) and not $('this').
dmarucco
A: 

Try this:

$('input[name=cancella]').click(function(){
  $(this).siblings().removeAttr('disabled');
}
Joel Harris