Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

247
Visualizações
How to pass "obj" to updateFinalTermScore(obj1) in onblur function?

I am using Datatables and trying to populate the datatable through an ajax call. In datatable I have added a textbox functionality so users can change the value of final marks. Once the user has changed the value of final marks I want to use a onblur function to save that new final marks value in database. So I have to pass rosterID and new final marks to the onblur function. But I don't know how to pass 2 parameters in this. I have decided to pass it an object named as "obj". But it is not passing at all to the function and formal parameter for the function "obj1" seems undefined. Here is my code.


// piece of code from my datatables AJAX call.
        { data: 'SrNo', title: "Sr No" },                               // 0
        { data: 'RosterID', title: "Roster ID", visible: false },       // 1
        { data: 'RollNo', title: "Roll No" },                           // 2
        { data: 'StudentName', title: "Student Name" },                 // 3
        {
           data: 'FinalScore', title: "Final Score",                   //4
           render: function (data, type, full, row) {
             var obj = {
               ros: full.RosterID,
               final: full.FinalScore
             }
           return '<input class="form-control" id="DTFinalaTermMarks" 
           name="DTFinalaTermMarks" type="text" onblur="updateFinalTermScore('+obj+');" 
           value = ' + data + '  >';
           }
         },                   
         { data: 'WeightedScore', title: "Weighted Score"},             //5
         

        // function with formal parameter
        function updateFinalTermScore(obj1) {
          var roterID = obj1.ros;
          alert("hi");
        }
        ```

kindly help.
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

The object you need to use is this.

updateFinalTermScore(this)

In the context of an event such as onblur, created in a column renderer, it would look like the following:

{ 
  title: "Salary", 
  data: "salary",
  render: function (data, type, row, meta) {
        
    return '<input class="form-control" id="DTFinalaTermMarks" ' + 
      'name="DTFinalaTermMarks" type="text" ' + 
      'onblur="updateFinalTermScore(this, ' + 
      '\'' + row.RosterID + '\'' + ');" ' + 
      'value = ' + data + '  >';
  }
}

The return statement uses string concatenation to create the required HTML.

The this object represents the context of the onblur event - the node for which the event happened. In this case, that is the relevant <input> element.

You need to use this approach so that you can access the value of the <input> element - which may have been updated by the user before the onblur event.

The resulting HTML created by the DataTables render function is:

<input class="form-control" 
       id="DTFinalaTermMarks" 
       name="DTFinalaTermMarks" 
       type="text" 
       onblur="updateFinalTermScore(this, '123');" value="456">

Here, 123 is the roster ID. I assume this is a string value, which is why I use '\'' to surround that value in single quotes.

When the onblur event happens, the updateFinalTermScore can access the node represented by this and extract the user-provided value using the jQuery val() function:

function updateFinalTermScore(node, salary) {
  console.log( $( node ).val() );
  console.log( RosterID );
}
about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda