Jump to content
Larry Ullman's Book Forums

webguru

Members
  • Posts

    3
  • Joined

  • Last visited

Everything posted by webguru

  1. Sorry Mr. San, I am unable make-out your point. Could you explain little bit more? Also is there any alternate option for this problem through PHP? Thanks.
  2. Thank you very much Mr. San, Your suggestion is fine, but the no of lines are coming to 135 i,e pipe_data[100][3][128] = [21.4, 100, 1.89, 3]; pipe_data[100][3][256] = [21.9, 100, 1.92, 3.5]; pipe_data[100][3][512] = [22.5, 100, 1.95, 3.9]; so this list goes up to 135 lines i.e for pipe - 15 values; pressure - 3valves; stiffness -3 values , resulting total lines would be 135 lines. whereas in the switch case, the lines are 135 - Hence there is no much difference in the code what you suggested. Instead of putting entire JavaScript code in the HTML, I would like to put in a external js file and link to the page so that there would be better speed. Dear Mr. San, I request your attention, is there any better method with PHP?
  3. Greetings everybody. I have written a code for my friend web for getting the weight; sp.gravity and wall thickness for the given Pipe diameter. All is working fine, but is there any better way to shorten the code? <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Pipe weight finder</title> <script language="JavaScript">function Cal(Atext, Btext, Ctext,form){ var A = parseFloat(Atext); var B = parseFloat(Btext); var C = parseFloat(Ctext); // here, the values for A= pipe dia; B= Pressure class; c=stiffness; //the chart vlaues for K = weight/rmt; L= Specfic Gravity; M= wall thickness in mm; N= hydro test pressure in Mpa. // the switch case statement goes in matrix manner // for ine valve of A = three valves of B; and nine valves of C switch (true){ case (A == 100 && B == 3 && C == 128): K =21.4; L =100; M =1.89; N=3; break ; case (A == 100 && B == 3 && C == 256): K =21.9; L=100; M=1.92; N=3.5; break ; case (A == 100 && B == 3 && C == 512): K =22.5; L=100; M=1.95; N=3.9; break ; case (A == 100 && B == 6 && C == 128): K =31.5; L=100; M=2.02; N=4.1; break ; case (A == 100 && B == 6 && C == 256): K =32.3; L=100; M=2.16; N=4.2; break ; case (A == 100 && B == 6 && C == 512): K =32.9; L=100; M=2.69; N=4.35;break ; case (A == 100 && B == 9 && C == 128): K =42.8; L=100; M=3.15; N=4.8; break ; case (A == 100 && B == 9 && C == 256): K =43.6; L=100; M=3.45; N=4.9; break ; case (A == 100 && B == 9 && C == 512): K =44.5; L=100; M=3.78; N=5.1; break ; case (A == 150 && B == 3 && C == 128): K =65.5; L=100; M=4.86; N=6.2; break ; case (A == 150 && B == 3 && C == 256): K =68.4; L=100; M=4.95; N=6.3; break ; case (A == 150 && B == 3 && C == 512): K =69.2; L=100; M=5.01; N=6.4; break ; // ... the code goes accordingly. // the code goes up to 1000 mm (i.e A=1000; B=9; C=512) } form.Ans1.value = K + " Kg/Rmt"; form.Ans2.value = Math.round((K*100/3.28)/100) + " Kg/Ft" ; form.Ans3.value = L; form.Ans4.value = M + " mm"; form.Ans5.value = N + " Mpa"; } </script> </head> <body> <div style="text-align=center; background-color: #C0C0C0; width:225px; height:450px; border:2px double blue;"> <P><FONT SIZE="+2">Pipe weight finder</FONT><hr color="#0099FF"> </P> <form name="ratefinder" method="post"> <P>Enter Pipe dia: <select name="input_A" > <option value="100">100 mm <option value="150">150 mm <option value="200">200 mm <option value="250">250 mm <!--the option value goes up to 1000 mm --> </select></p> <P>Enter Pressure: <select name="input_B" > <option value="3"> 3 Kg <option value="6"> 6 Kg <option value="9"> 9 Kg </select></p> <P>Enter Stiffness: <select name="input_C" > <option value="128"> 128 <option value="256"> 256 <option value="512"> 512 </select></p> <P><input type="button" VALUE="SUBMIT" onClick="Cal(this.form.input_A.value, this.form.input_B.value, this.form.input_C.value, this.form)"> <input type="Reset" name="reset" value ="RESET" onClick ="(this.form);" /></P> <hr color="#0099FF"> <P>Weight: <input type=text name="Ans1" SIZE=10></P> <P>Weight /Feet: <input type=text name="Ans2" SIZE=10></P> <P>Sp.Gravity: <input type=text name="Ans3" SIZE=10></P> <P>Wall Thickness: <input type=text name="Ans4" SIZE=10></P> <P>Hydro testing: <input type=text name="Ans5" SIZE=10></P> </form> </div> </body> </html> Even though the code works fine but: Due to long JavaScript line, the page getting slower. As the JS code is Matrix manner & the value are more than 15 x 3 x3 = 135 switch cases; Kindly suggest is there any better way though PHP? Thanking you.
×
×
  • Create New...