By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,946 Members | 1,714 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,946 IT Pros & Developers. It's quick & easy.

Form with some calculation but input fields are resulting to NaN.

P: 1
I am trying to do some calculation with this form but some input fields are resulting NaN. Can anyone explain the error and a fix? Thanks


Expand|Select|Wrap|Line Numbers
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  2. <html xmlns="http://www.w3.org/1999/xhtml">
  3. <head>
  4. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  5. <title>Coil Cord Calculator</title>
  6. <script language="JavaScript">
  7.  
  8. function calculate() 
  9. {    
  10.  
  11. majorOD = Number(document.catalog_form.majorOD.value);
  12. BodyLength = Number(document.catalog_form.BodyLength.value);
  13. CoilsNCord = Number(BodyLength/majorOD);
  14. document.catalog_form.CoilsNCord.value = CoilsNCord;
  15.  
  16. mandrelSize = Number(document.catalog_form.mandrelSize.value);                     
  17. CCD = Number((1.2*mandrelSize)+(2*majorOD));
  18. document.catalog_form.CCD.value = CCD;
  19.  
  20. FCCB = Number((3.14159*BodyLength)*(CCD-majorOD)/majorOD)/12;
  21. document.catalog_form.FCCB.value = FCCB;
  22.  
  23. TanA = Number(document.catalog_form.TanA.value);
  24. TanB = Number(document.catalog_form.TanB.value);
  25. FCCC = Number(FCCB+((TanA+TanB)/12));
  26. document.catalog_form.FCCC.value = FCCC;
  27.  
  28. jacket = Number(document.catalog_form.jacket_2.value);
  29. ExtNoTan = Number(jacket*FCCB); 
  30. document.catalog_form.ExtNoTan_2.value = ExtNoTan;
  31. MinEx = Number(ExtNoTan+(0.12*ExtNoTan));   
  32. document.catalog_form.MinEx_2.value = MinEx;  
  33. MaxEx = Number(MinEx+(0.24*MinEx)); 
  34. document.catalog_form.MaxEx_2.value = MaxEx;
  35. }
  36.  
  37. function displayPercent(jacket)
  38. {
  39. document.getElementById("ExtPer").value=jacket
  40. }
  41.  
  42. </script>
  43.  
  44.  
  45. </head>
  46.  
  47. <body>
  48.  
  49.  
  50. <form name="catalog_form">
  51. <table width="946" border="1" cellpadding="3" cellspacing="5">
  52.     <tr>
  53.     <td colspan="5" align="center"><h1>Coil Cord Calculator</h1> </td>
  54.   </tr>
  55.   <tr>
  56.     <td width="270">&nbsp;</td>
  57.     <td width="319">&nbsp;</td>
  58.     <td colspan="2">Mandrel Sizes Available:</td>
  59.     <td width="145"></td>
  60.   </tr>
  61.   <tr>
  62.     <td width="270">Cable Major OD: <input type="text" name="majorOD" size="10"></td>
  63.     <td width="319"># Coils in Cord: 
  64.       <input type="text" name="CoilsNCord" size="10" disabled="disabled"/></td>
  65.     <td width="70" rowspan="10" align="center" valign="top">1/8&quot;<br />
  66. 3/16&quot;<br />
  67. 5/16&quot;<br />
  68. .355&quot;<br />
  69. 3/8&quot;<br />
  70. 7/16&quot;<br />
  71. 1/2&quot;<br />
  72. .720&quot;<br />
  73. 1&quot;<br />
  74. 3&quot;</td>
  75.     <td width="70" rowspan="10" align="center" valign="top">.125&quot;<br />
  76. .1875&quot;<br />
  77. .25&quot;<br />
  78. .355&quot;<br />
  79. .375&quot;<br />
  80. .4375&quot;<br />
  81. .500&quot;<br />
  82. .720&quot;<br />
  83. 1&quot;<br />
  84. 3&quot;</td>
  85.     <td width="145">&nbsp;</td>
  86.   </tr>
  87.   <tr>
  88.     <td>Cable Minor OD: <input type="text" name="MinorOD" size="10" onChange=calculate();></td>
  89.     <td>Coil Diameter:      
  90.       <input type="text" name="CCD" size="10" disabled="disabled"/></td>
  91.     <td>&nbsp;</td>
  92.   </tr>
  93.    <tr>
  94.     <td>Mandrel Size: <input type="text" name="mandrelSize" size="10" onChange=calculate();></td>
  95.     <td>Ft. of Cable in Coil Body: 
  96.       <input type="text" name="FCCB" size="10" disabled="disabled"/></td>
  97.     <td>&nbsp;</td>
  98.   </tr>
  99.    <tr>
  100.     <td>Body Length: <input type="text" name="BodyLength" size="10" onChange=calculate();></td>
  101.     <td>Ft. of Cable in Coil Cord:      
  102.       <input type="text" name="FCCC" size="10" disabled="disabled"/></td>
  103.     <td>&nbsp;</td>
  104.   </tr>
  105.    <tr>
  106.     <td>Tangent A: <input type="text" name="TanA" size="10" onChange=calculate();></td>
  107.     <td></td>
  108.     <td>&nbsp;</td>
  109.   </tr>
  110.    <tr>
  111.     <td>Tangent B: <input type="text" name="TanB" size="10" onChange=calculate();></td>
  112.     <td></td>
  113.     <td>&nbsp;</td>
  114.   </tr>
  115.    <tr>
  116.     <td></td>
  117.     <td>Minimum Extended:      
  118.       <input type="text" name="MinEx_2"  style="background-color:yellow" size="10" disabled="disabled"/></td>
  119.     <td>&nbsp;</td>
  120.   </tr>
  121.   <tr>
  122.     <td>Extension Percent: <input type="text" name="ExtPer" value=".70" id="ExtPer" size="10" disabled="disabled" onChange=calculate();/>
  123. </td>
  124.     <td>Extension Without Tangent:      
  125.       <input type="text" name="ExtNoTan_2" style="background-color:yellow" size="10" disabled="disabled"/></td>
  126.     <td>&nbsp;</td>
  127.   </tr>
  128.   <tr>
  129.     <td></td>
  130.     <td>Maximum Extended:      
  131.       <input type="text" name="MaxEx_2" style="background-color:yellow" size="10" disabled="disabled"/></td>
  132.     <td>&nbsp;</td>
  133.   </tr>
  134.   <tr>
  135.     <td></td>
  136.     <td></td>
  137.     <td>&nbsp;</td>
  138.   </tr>
  139.    <tr>
  140.     <td colspan="2" align="center">Cable Construction</td>
  141.     <td colspan="2" align="center">&nbsp;</td>
  142.     <td>&nbsp;</td>
  143.   </tr>
  144.   <tr>
  145.     <td colspan="2" valign="top"><p>
  146.       <input type="radio" name="jacket" onClick="displayPercent(this.value)" value=".70" checked="checked">Polyurethane Jacket<br />
  147. <input type="radio" name="jacket" onClick="displayPercent(this.value)" value=".65">TPE Jacket<br />
  148. <input type="radio" name="jacket" onClick="displayPercent(this.value)" value=".60">Polypropylene or Hytrel primaries with PVC Jacket 
  149. <br />
  150. <input type="radio" name="jacket" onClick="displayPercent(this.value)" value=".55">PVC primaries with PVC jacket 
  151. <br />
  152. <input type="radio" name="jacket" onClick="displayPercent(this.value)" value=".50">Other<br />     </p></td>
  153.     <td colspan="2" align="center"><p>&nbsp;</p>      <p>&nbsp;</p></td>
  154.    <td>&nbsp;</td>
  155.   </tr>
  156.  
  157. </table>
  158.  
  159. </form>  
  160. </body>
  161. </html>
Apr 26 '11 #1
Share this Question
Share on Google+
1 Reply


Dormilich
Expert Mod 5K+
P: 8,639
I only can explain why. you get NaN when the input canít be converted to a number (hence NaN Ė Not a Number).
Apr 27 '11 #2

Post your reply

Sign in to post your reply or Sign up for a free account.