Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. Web Development
  3. JavaScript
  4. Trying to read a value that is coming from html() function from Table Cell Id

Trying to read a value that is coming from html() function from Table Cell Id

Scheduled Pinned Locked Moved JavaScript
javascripthtmlhelpquestion
8 Posts 2 Posters 22 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    simpledeveloper
    wrote on last edited by
    #1

    Hi, I am trying to read a value from Table Cell, but even if I am using parseFloat, Number or any function its always returning me null value, hence total is coming as null from the below code of JavaScript, any help please?

    if ((m.PaymentPlan.ViolationsUniquePenaltyApplied != null) && (m.PaymentPlan.ViolationsUniquePenaltyApplied != 'undefined'))
    for (let i = 0; i < m.PaymentPlan.ViolationsUniquePenaltyApplied.length; i++) {
    let t = '#' + 'td0' + i;
    let a = parseFloat($(t).html());
    let b = Number($(t).html());
    console.log('a');
    console.log(a);
    console.log(b);
    totalRemaining = parseFloat(totalRemaining) - a;
    console.log('totalRemaining');
    console.log(totalRemaining);
    }

    L 1 Reply Last reply
    0
    • S simpledeveloper

      Hi, I am trying to read a value from Table Cell, but even if I am using parseFloat, Number or any function its always returning me null value, hence total is coming as null from the below code of JavaScript, any help please?

      if ((m.PaymentPlan.ViolationsUniquePenaltyApplied != null) && (m.PaymentPlan.ViolationsUniquePenaltyApplied != 'undefined'))
      for (let i = 0; i < m.PaymentPlan.ViolationsUniquePenaltyApplied.length; i++) {
      let t = '#' + 'td0' + i;
      let a = parseFloat($(t).html());
      let b = Number($(t).html());
      console.log('a');
      console.log(a);
      console.log(b);
      totalRemaining = parseFloat(totalRemaining) - a;
      console.log('totalRemaining');
      console.log(totalRemaining);
      }

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      What is the actual text returned from $(t).html() ?

      S 1 Reply Last reply
      0
      • L Lost User

        What is the actual text returned from $(t).html() ?

        S Offline
        S Offline
        simpledeveloper
        wrote on last edited by
        #3

        1000.00

        L 1 Reply Last reply
        0
        • S simpledeveloper

          1000.00

          L Offline
          L Offline
          Lost User
          wrote on last edited by
          #4

          when I try the code I get NaN, most likely because totalRemaining is not defined before it is used in the final expression.

          S 1 Reply Last reply
          0
          • L Lost User

            when I try the code I get NaN, most likely because totalRemaining is not defined before it is used in the final expression.

            S Offline
            S Offline
            simpledeveloper
            wrote on last edited by
            #5

            No totalRemaining is also printing as 5000.00, but when I am trying to add them its retuning NaN My total function as below:

                    saveTotalPenalty: function (paramdata, id, indx) {
                        var m = this.get('model');
            
                        let totalRemaining = m.PaymentPlan.TotalAmount;               
            
                        this.penaltyPerUnit = $(this.boxId).val() / paramdata.Cnt;
                        this.penaltyPerUnit = this.penaltyPerUnit.toFixed(2);
            
                        if ((m.PaymentPlan.ViolationsUniquePenaltyApplied != null) && (m.PaymentPlan.ViolationsUniquePenaltyApplied != 'undefined'))
                            for (let i = 0; i < m.PaymentPlan.ViolationsUniquePenaltyApplied.length; i++) {
                                let t = '#' + 'td0' + i;
                                let a = parseFloat($(t).html().valueOf());
                               
                                console.log('a');
                                console.log(a);
                                totalRemaining = parseFloat(totalRemaining) - a;
                                console.log('totalRemaining');
                                console.log(totalRemaining);
                            }
            
                        if ((m.PaymentPlan.ViolationsUniquePenaltyNotApplied != null) && (m.PaymentPlan.ViolationsUniquePenaltyNotApplied != 'undefined'))
                            for (let i = 0; i < m.PaymentPlan.ViolationsUniquePenaltyNotApplied.length; i++) {
                                let t = '#' + 'txt' + i;
                                totalRemaining = totalRemaining - $(t).val();
                            }
            
                        totalRemaining = totalRemaining.toFixed(2);
                        $('#thTotalRemaining').html(totalRemaining)                
            
                        if ((paramdata.PenaltyAssessed == null) || (paramdata.PenaltyAssessed == 0) || (paramdata.PenaltyAssessed == 'undefined') || isNaN(paramdata.PenaltyAssessed))
                            return;
            
                        $('#td' + indx).html(this.penaltyPerUnit);
                        var scope = this;
                        var data = {
                            violationPenaltyAdjustment: paramdata,
                            CaseId: id,
                            PenaltyAssessed: paramdata.PenaltyAssessed
                        };              
            
                        scope.api('Paymentxxxn/AddTotalxxxx').post(data).then(function (response) {
                            //scope.set('model', response.Data.plan);
                            toastr.success("Payment added");
                        }, function (error) {
                            Ember.set(payment, "isLoading", false);
                            toastr.erro
            
            L 1 Reply Last reply
            0
            • S simpledeveloper

              No totalRemaining is also printing as 5000.00, but when I am trying to add them its retuning NaN My total function as below:

                      saveTotalPenalty: function (paramdata, id, indx) {
                          var m = this.get('model');
              
                          let totalRemaining = m.PaymentPlan.TotalAmount;               
              
                          this.penaltyPerUnit = $(this.boxId).val() / paramdata.Cnt;
                          this.penaltyPerUnit = this.penaltyPerUnit.toFixed(2);
              
                          if ((m.PaymentPlan.ViolationsUniquePenaltyApplied != null) && (m.PaymentPlan.ViolationsUniquePenaltyApplied != 'undefined'))
                              for (let i = 0; i < m.PaymentPlan.ViolationsUniquePenaltyApplied.length; i++) {
                                  let t = '#' + 'td0' + i;
                                  let a = parseFloat($(t).html().valueOf());
                                 
                                  console.log('a');
                                  console.log(a);
                                  totalRemaining = parseFloat(totalRemaining) - a;
                                  console.log('totalRemaining');
                                  console.log(totalRemaining);
                              }
              
                          if ((m.PaymentPlan.ViolationsUniquePenaltyNotApplied != null) && (m.PaymentPlan.ViolationsUniquePenaltyNotApplied != 'undefined'))
                              for (let i = 0; i < m.PaymentPlan.ViolationsUniquePenaltyNotApplied.length; i++) {
                                  let t = '#' + 'txt' + i;
                                  totalRemaining = totalRemaining - $(t).val();
                              }
              
                          totalRemaining = totalRemaining.toFixed(2);
                          $('#thTotalRemaining').html(totalRemaining)                
              
                          if ((paramdata.PenaltyAssessed == null) || (paramdata.PenaltyAssessed == 0) || (paramdata.PenaltyAssessed == 'undefined') || isNaN(paramdata.PenaltyAssessed))
                              return;
              
                          $('#td' + indx).html(this.penaltyPerUnit);
                          var scope = this;
                          var data = {
                              violationPenaltyAdjustment: paramdata,
                              CaseId: id,
                              PenaltyAssessed: paramdata.PenaltyAssessed
                          };              
              
                          scope.api('Paymentxxxn/AddTotalxxxx').post(data).then(function (response) {
                              //scope.set('model', response.Data.plan);
                              toastr.success("Payment added");
                          }, function (error) {
                              Ember.set(payment, "isLoading", false);
                              toastr.erro
              
              L Offline
              L Offline
              Lost User
              wrote on last edited by
              #6

              I just tried with totalRemaining set to 5000, and the results are correct. There must be something else happening in your code.

              S 1 Reply Last reply
              0
              • L Lost User

                I just tried with totalRemaining set to 5000, and the results are correct. There must be something else happening in your code.

                S Offline
                S Offline
                simpledeveloper
                wrote on last edited by
                #7

                No actually when I am printing as below:

                console.log('$(t).html()');
                console.log($(t).html());
                let a = parseFloat($(t).html());
                console.log('a');
                console.log(a);

                console.log($(t).html()); is printing 1000 but after doing this, it is printing a value as NaN, any help please?

                L 1 Reply Last reply
                0
                • S simpledeveloper

                  No actually when I am printing as below:

                  console.log('$(t).html()');
                  console.log($(t).html());
                  let a = parseFloat($(t).html());
                  console.log('a');
                  console.log(a);

                  console.log($(t).html()); is printing 1000 but after doing this, it is printing a value as NaN, any help please?

                  L Offline
                  L Offline
                  Lost User
                  wrote on last edited by
                  #8

                  Sorry, there is nothing more I can do. When I run those few lines of code I get the correct answer. But I cannot reproduce your problem since i do not have all the code.

                  1 Reply Last reply
                  0
                  Reply
                  • Reply as topic
                  Log in to reply
                  • Oldest to Newest
                  • Newest to Oldest
                  • Most Votes


                  • Login

                  • Don't have an account? Register

                  • Login or register to search.
                  • First post
                    Last post
                  0
                  • Categories
                  • Recent
                  • Tags
                  • Popular
                  • World
                  • Users
                  • Groups