0

enter image description here

Any one can help me get the value from the Table td with the price. Thanks

$(document).ready(function () {
    var v = parseInt(
        $(".product-table:first-child .product-table__col--totals")
            .text().trim().replace(',', '')
    );
    var totalValue = v / 3 + 6090;
    console.log(totalValue);
    $("#subscipt_total").text("After multiplying the Value 10=" + totalValue);
});
Dmitry Barskov
  • 1,200
  • 8
  • 14
  • which TD you are talking about from your image? – Atul Rajput Apr 28 '21 at 07:55
  • Subscription Total: $994,500.00 in the first table with Subscruption Total sir. I want to get the value and divide it by 3 + the $6,090. and append the value to a div. So sorry I am not too good on coding hope I can have the results with all your helps :( – Neil Junsan Apr 28 '21 at 08:08

2 Answers2

0

As NaN represents an error as a result of the parse not being an actual number(see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/NaN). You're most likely grabbing the numerical value from a column that contains more than just numbers. If you log

$(".product-table:first-child .product-table__col--totals")
      .text()
      .trim() 
      .replace(',', ''));

EDIT:: After discussion in the comments we found out that the TD that OP was trying to parse as an integer in fact contained the following string: "Subscription Total: $994,500.00". by using the snippet seen below

$(".product-table:first-child .product-table__col--totals")
.text()
.split('$')[1]
.replace(',','') 

the sought after integer was acquired.

  • Sorry sir, Not too good on coding I need help , Just found that code by using span tag not a table td so wondering why its NAN value :( – Neil Junsan Apr 28 '21 at 08:10
  • if you run `console.log($(".product-table:first-child .product-table__col--totals").text().trim() .replace(',', '')));`, what does the output look like? – MaxStrandberg Apr 28 '21 at 08:12
  • The results is "Uncaught SyntaxError: Unexpected token ')'" sir. sorry – Neil Junsan Apr 28 '21 at 08:15
  • Can you give some sample code that gets the value inside td tag of "Subscription Total: $994,500.00" getting that value and append to another div or li tag sir? :( – Neil Junsan Apr 28 '21 at 08:18
  • If the value inside the td tag is "Subscription Total: $994,500.00" you can run something along the lines of `$(".product-table:first-child .product-table__col--totals").text().split('$')[1].replace(',','')` and it should give you "994500.00" as a result, can you try it? – MaxStrandberg Apr 28 '21 at 08:34
  • Awesome I can see the results 994500 already with after "\n\t\t\t\t\t\t\t\t\t\t\t\t\t\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tOne-Time Fees Total:\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t" I am getting the value closer .. do we have a format on to display the number on currency i mean with comma 994,500 sir ? – Neil Junsan Apr 28 '21 at 08:39
  • If you've acquired the sought after number value and stored it in say totalValue with the previous code snippet, you can use something along the lines of `totalValue.toLocaleString()`, it might not be supported accross all browsers though, a more stable solution is `totalValue.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",");` see https://stackoverflow.com/questions/2901102/how-to-print-a-number-with-commas-as-thousands-separators-in-javascript for more information – MaxStrandberg Apr 28 '21 at 08:45
  • BTW sir with implementing that tostring inorder to have comma do the code looks like this sir ? where should i put this line of code "totalValue.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",");" Thanks a lot! `code` $(document).ready(function () { var v = parseInt($(".product-table:first-child .product-table__col--totals")totalValue.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",")); var totalValue = v / 3 + 6090; console.log(totalValue); $("#subscipt_total").text("$" + totalValue + " Due NET 30"); }); `code` – Neil Junsan Apr 28 '21 at 08:51
  • You can create a variable like `var formattedValue = totalValue.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",");` and then you use that variable to set the text of the html-object which holds the value, so as an example like this: `$("#subscipt_total").text("$" + formattedValue + " Due NET 30");`, but it of course depends on where you want the result to be shown. – MaxStrandberg Apr 28 '21 at 08:55
  • OMG I don't know how I thank you for your kind sir. You are a hero. BTW sir ,, can you check this link https://7475627.hubspotpreview-na1.com/_hcms/preview/template/multi?domain=undefined&hs_preview_key=ZufopZGQDPwUbT0B0cY2zA&portalId=7475627&tc_deviceCategory=undefined&template_file_path=Marketplace/HubSpotSiteSetup/Vast_Site_Setup/Templates/Custom_Template/panzura-quotes-annual-payment.html&updated=1619513799510& under the Payment Terms in the "$0.00 Due 06/03 20211" the 2021 year I want to loop it + 1 year it should be 2022 is it possible to set a code on that one ? – Neil Junsan Apr 28 '21 at 09:00
  • If my answer is helpful for you, you can accept it as answer( click on the check mark beside the answer to toggle it from greyed out to filled in.). See meta.stackexchange.com/questions/5234/…. This can be beneficial to other community members. Thank you. – MaxStrandberg Apr 28 '21 at 09:04
  • I am unable to access the link you posted, can you post an image? – MaxStrandberg Apr 28 '21 at 09:09
  • Got it sir. will check the mark the answer btw , Is it possible to loop a year e.g 2021 we can add + 1 year so it will be 2022 sir and so on 2023 – Neil Junsan Apr 28 '21 at 09:09
  • Oh so sorry here https://i.stack.imgur.com/sry0r.png in the bottom theres a year 20211 i tried to + 1 the year so it will be 2022 instead what the results is it added as digit number. – Neil Junsan Apr 28 '21 at 09:11
  • If you want to see how to add a year or more to a date i'd recommend looking at the following post https://stackoverflow.com/questions/33070428/add-a-year-to-todays-date – MaxStrandberg Apr 28 '21 at 09:14
  • I just saw the image, the date element of your code is most likely a string type, so when you do date + 1 it interprets it as "06/03 2021" + "1" which results in an append => "06/03 20211". – MaxStrandberg Apr 28 '21 at 09:15
  • You are right sir its string thanks I will look the link you have posted thanks – Neil Junsan Apr 28 '21 at 09:16
  • Hi sir i tried to look up the link I tried to set the date get the value of e.g `code 2021 ` Can we still have get that value as string like we did from the price and just add +1 to this tag `code 2022 ` Is it possible to just get the value of the first one and just add + 1 and append to the class of 2nddate sir ? – Neil Junsan Apr 28 '21 at 09:30
  • yes ofc, if you do something like `$(".2nddate").text(parseInt($(".startdate")) + 1)` it should work – MaxStrandberg Apr 28 '21 at 09:35
  • Sir tried to run the code `code $(".datedate2").text(parseInt($(".startdate")) + 1); $(".datedate3").text(parseInt($(".startdate")) + 2);` The results is Nan: hope you can help me figure this out $337,590 Due NET 30 2021 $331,500 Due 03/09 NaN $331,500 Due 03/09 NaN – Neil Junsan Apr 28 '21 at 10:50
  • The element $(".startdate")) contains more than just numbers then, as you're trying to convert something that isn't a number into a number – MaxStrandberg Apr 29 '21 at 07:24
  • Thanks sir , I got it working now. Do you have idea about this line of code `code{{ QUOTE_PROPS.hs_createdate|int|datetimeformat('%m/%d', TIMEZONE, LOCALE) }}` The results on the time format is 03/09/2021 i want to make it long format to be like this MARCH 09, 2021 i treid to change this one "%MM/%DD'" the results is NAN. thanks – Neil Junsan Apr 29 '21 at 07:50
0

You have “$” currency character thats why you are getting NAN, so you need to replace that too along with comma “,”.

var v = parseInt($(".product-table:first-child .product-table__col--totals")
      .text()
      .trim() 
      .replace(/,|$/g, ''));
Rahul Kumar
  • 3,009
  • 2
  • 16
  • 22
  • It is still Nan sir here's the link of the page https://7475627.hubspotpreview-na1.com/_hcms/preview/template/multi?domain=undefined&hs_preview_key=ZufopZGQDPwUbT0B0cY2zA&portalId=7475627&tc_deviceCategory=undefined&template_file_path=Marketplace/HubSpotSiteSetup/Vast_Site_Setup/Templates/Custom_Template/panzura-quotes-annual-payment.html&updated=1619513799510& – Neil Junsan Apr 28 '21 at 08:31
  • NAN error is coming before console.log(totalValue) or after? – Rahul Kumar Apr 28 '21 at 08:35