• 1

Read this first!

We do not monitor these forums. The forum is provided to exchange information and experience with other users ONLY. Forum responses are not guaranteed.

However, please submit a ticket if you have an active subscription and wish to receive support. Our ticketing system is the only way of getting in touch with RSJoomla! and receiving the official RSJoomla! Customer Support.

For more information, the Support Policy is located here.

Thank you!

TOPIC: The strange result = NaN

The strange result = NaN 13 years 4 months ago #15726

Hi guys, I have one problem whit this code:
function calculateTextmega()
{
var op600=document.getElementById('MEGATOTALE_A');
var op601=document.getElementById('MEGATOTALE_B');
var op602=document.getElementById('MEGATOTALE_C');
var op603=document.getElementById('MEGATOTALE_D');
var op604=document.getElementById('MEGATOTALE_E');
var op605=document.getElementById('MEGATOTALE_F');
var op606=document.getElementById('MEGATOTALE_G');
var op607=document.getElementById('MEGATOTALE_H');
var op608=document.getElementById('MEGATOTALE_I');
var op609=document.getElementById('MEGATOTALE_L');
var op610=document.getElementById('MEGATOTALE_M');
var result=document.getElementById('MEGATOTALE2');
var shipcost=document.getElementById('spedizione');
 
document.getElementById('MEGATOTALE2').value = (result.value);
document.getElementById('MEGATOTALE').value = parseInt('MEGATOTALE2').value+parseInt('spedizione').value;
 
if(op600.value=="" || op600.value!=parseFloat(op600.value)) op600.value=0.0;
if(op601.value=="" || op601.value!=parseFloat(op601.value)) op601.value=0.0;
if(op602.value=="" || op602.value!=parseFloat(op602.value)) op602.value=0.0;
if(op603.value=="" || op603.value!=parseFloat(op603.value)) op603.value=0.0;
if(op604.value=="" || op604.value!=parseFloat(op604.value)) op604.value=0.0;
if(op605.value=="" || op605.value!=parseFloat(op605.value)) op605.value=0.0;
if(op606.value=="" || op606.value!=parseFloat(op606.value)) op606.value=0.0;
if(op607.value=="" || op607.value!=parseFloat(op607.value)) op607.value=0.0;
if(op608.value=="" || op608.value!=parseFloat(op608.value)) op608.value=0.0;
if(op609.value=="" || op609.value!=parseFloat(op609.value)) op609.value=0.0;
if(op610.value=="" || op610.value!=parseFloat(op610.value)) op610.value=0.0;
 
result.value=0;
result.value=parseFloat(result.value);
result.value=parseFloat(result.value)+parseFloat(op600.value)+parseFloat(op601.value)+parseFloat(op602.value)+parseFloat(op603.value)+parseFloat(op604.value)+parseFloat(op605.value)+parseFloat(op606.value)+parseFloat(op607.value)+parseFloat(op608.value)+parseFloat(op609.value)+parseFloat(op610.value);
 
if(result.value>0 && result.value<100) shipcost.value=19.00;
if(result.value>101 && result.value<200) shipcost.value=35.00;
if(result.value>201 && result.value<300) shipcost.value=39.00;
if(result.value>301 && result.value<400) shipcost.value=52.00;
if(result.value>401 && result.value<500) shipcost.value=52.00;
if(result.value>501 && result.value<10000000) shipcost.value=result.value*0.025+result.value;
 
}

I search the solution, but I look ONLY NaN result! WHY?:unsure: :unsure:
The administrator has disabled public write access.

Re: The strange result = NaN 13 years 4 months ago #15739

  • andreic
  • andreic's Avatar
  • OFFLINE
  • RSJoomla! Official Staff
  • Posts: 745
  • Thank you received: 66
Hello,

Please try moving
document.getElementById('MEGATOTALE2').value = (result.value);
document.getElementById('MEGATOTALE').value = parseInt('MEGATOTALE2').value+parseInt('spedizione').value;

at the end of your script, right before the closing "}". If you are still encountering the NaN (not a number) value in your field, please double check the calculations that are performed in order to obtain the total.
Please note: my help is not official customer support. To receive your support, submit a ticket by clicking here
Regards,
RSJoomla! Development Team
The administrator has disabled public write access.

Re: The strange result = NaN 13 years 4 months ago #15743

THANK YOU SO MUCH!
I solved!:laugh:
andreic wrote:
Hello,

Please try moving
document.getElementById('MEGATOTALE2').value = (result.value);
document.getElementById('MEGATOTALE').value = parseInt('MEGATOTALE2').value+parseInt('spedizione').value;

at the end of your script, right before the closing "}". If you are still encountering the NaN (not a number) value in your field, please double check the calculations that are performed in order to obtain the total.
The administrator has disabled public write access.

Re: The strange result = NaN 10 years 8 months ago #28500

  • luckgood
  • luckgood's Avatar
  • OFFLINE
  • Fresh Boarder
  • Posts: 1
Help Me! :ohmy:
I want to calculate the difference in days between two calendar dates. Using this materials, as a result I've got next answer: NAN. What it's mean?
This is my script:
<script type="text/javascript">
function calculateDate(date1, date2){
 
  diffc = date1.getTime() - date2.getTime();
 
  days = Math.round(Math.abs(diffc/(1000*60*60*24)));
 
return days;
}
 
function rsfp_onSelectDate(date, type, args, calendar){
 
argsstr = String(args);
spldate = argsstr.split(",");
date1 = new Date(spldate[0],spldate[1]-1,spldate[2]);
 
date2 = ' ';
 
if(calendar.myid == 'cal6_0' && RSFormProCalendars[6]['calendar2'].getSelectedDates() != '')
  date2 = new Date(RSFormProCalendars[6]['calendar2'].getSelectedDates());
 
if(calendar.myid == 'cal6_1' && RSFormProCalendars[6]['calendar1'].getSelectedDates() != '')
  date2 = new Date(RSFormProCalendars[6]['calendar1'].getSelectedDates());
 
if(date2 != ' '){
  days = calculateDate(date1, date2);
  document.getElementById('raznitsa').value = days;
}
return true;
}
</script>

Thanks!
The administrator has disabled public write access.

Re: The strange result = NaN 10 years 8 months ago #28505

  • cosmin.cristea
  • cosmin.cristea's Avatar
  • OFFLINE
  • Platinum Boarder
  • Posts: 756
  • Thank you received: 144
I have tried the code provided in your reply (with the given changes to the form ID and field names) and it works as intended. Please make sure you're using the exact form id and names for the calendar fields. Nan is usually used to indicate an error condition for a function that should return a valid number.
My help is not official customer support. To receive your support, submit a ticket by clicking here
The administrator has disabled public write access.
  • 1

Read this first!

We do not monitor these forums. The forum is provided to exchange information and experience with other users ONLY. Forum responses are not guaranteed.

However, please submit a ticket if you have an active subscription and wish to receive support. Our ticketing system is the only way of getting in touch with RSJoomla! and receiving the official RSJoomla! Customer Support.

For more information, the Support Policy is located here.

Thank you!