C
C
ChernovDmitry2013-03-27 14:40:20
JavaScript
ChernovDmitry, 2013-03-27 14:40:20

Can you please explain why this code does not work?

Imagine that there is an html table in the admin panel with columns: username, something else and the "Ban" button. When you click on the button, an ajax request is sent and, in theory, the text of the button changes to "Unban". This is exactly what I can not achieve (Ie, the inscription on the button does not change). Please explain what I'm doing wrong.

Utils.bahn = function( index ) {<br>
  // table bahn_list select<br>
  var row = $('#bahn_list tr').eq( index + 1 )[0];<br>
  var name = row.cells[0].innerHTML;<br>
  <br>
  var input = $( row.cells[3].innerHTML );<br>
  <br>
  if( input.val() == "Зобанить" ) {<br>
    Utils.sendPackage( Utils.createBahnPackage(name) );<br>
    input.val( "Розбанить" );<br>
    input.attr('value', 'Розбанить');<br>
  }<br>
  else if( input.val() == "Розбанить" ) {<br>
    Utils.sendPackage( Utils.createUnBahnPackage(name) );<br>
    input.val( "Зобанить" );<br>
  }<br>
}<br>

Answer the question

In order to leave comments, you need to log in

2 answer(s)
O
Oleg Matrozov, 2013-03-27
@ChernovDmitry

Doesn't work because

var input = $( row.cells[3].innerHTML );

will not return the current object (apparently you have
<input type="button">
lies), but will create a new one, to which it will change its value.

T
tarzan82, 2013-03-28
@tarzan82

In my opinion, since you are already using jquery, you do not need to interfere with it with native code.
your piece

var row = $('#bahn_list tr').eq( index + 1 )[0];
var name = row.cells[0].innerHTML;
var input = $( row.cells[3].innerHTML );

can be replaced with
var row = $('#bahn_list tr').eq(index + 1);
var name = $('td:first', row).html();
var input = $('td:eq(3) > input', row);

And yet, why this double?
input.val( "Розбанить" );
input.attr('value', 'Розбанить');

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question