Jump to content


Check out our Community Blogs

Register and join over 40,000 other developers!


Recent Status Updates

View All Updates

Photo
- - - - -

Problem With A Function?(Jquery + Big Function)

jQuery jquery

  • Please log in to reply
7 replies to this topic

#1 Hamed

Hamed

    CC Devotee

  • Senior Member
  • PipPipPipPipPipPip
  • 413 posts

Posted 12 April 2012 - 05:12 AM

Hello,
I code this function but it looks it have problem:
<script lang="javascript" type="text/javascript">
function calculate(){
   var cloValue = $("#clo").val();
   var metValue = $("#met").val();
   var paValue = $("#pa").val();
   var rhValue = $("#rh").val();
   var trValue = $("#tr").val();
   var taValue = $("#ta").val();
   var wmeValue = $("#wme").val();
   var velValue = $("#vel").val();
   var icl, m, w, mw, fcl, hcf, taa, tra, tcla, p1, p2, p3, p4, p5;
   var xn, xf, eps, tcl, hl1, hl2, hl3, hl4, hl5, hl6, ts, pwv, ppd;
   var hcn = 0, hc = 0;
   int n = 0, flag = 0;
   if(paValue == 0) {
	    paValue = rhValue * 10 * Math.exp(16.6536 - (4030.183 / (taValue + 235)));
   }
   icl = 0.155 * cloValue;
   m = metValue * 58.15;
   w = wmeValue * 58.15;
   mw = m - w;
   if (icl < 0.078) {
		    fcl = 1 + 1.29 * icl;
   } else {
		    fcl = 1.05 + 0.645 * icl;
   }
   hcf = 12.1 * Math.pow(velValue, 0.5);
   taa = taValue + 273;
   tra = trValue + 273;
   tcla = taa + (35.5 - taValue) / (3.5 * (6.45 * icl + 0.1));
   p1 = icl * fcl;
   p2 = p1 * 3.96;
   p3 = p1 * 100;
   p4 = p1 * taa;
   p5 = 308.7 - 0.028 * mw + p2 * Math.pow((tra / 100) ,4);
   xn = tcla /100;
   xf = tcla /50;
   n = 0;
   flag = 0;
   eps = 0.0015;
   while (Math.abs(xn - xf) > eps)
   {
	    xf = (xf + xn) / 2;
	    hcf = 12.1 * Math.pow(velValue, 0.5);
	    hcn = 2.38 * Math.pow(Math.abs((100 * xf) - taa), 0.25);
	    if (hcf > hcn)
	    {
			    hc = hcf;
	    } else {
			    hc = hcn;
	    }
	    xn = (p5 + p4 * hc - p2 * Math.pow(xf, 4)) / (100 + p3 * hc);
	    n++;
	    if(n > 150)
	    {
		    flag = 1;
		    break;
	    }
   }
   tcl = 100 * xn - 273;
   if(flag == 0)
   {
	    hl1 = 3.05 * 0.001 * (5733 - 6.99 * mw - paValue);
	    if(mw > 58.15){
		    hl2 = 0.42 * (mw - 58.15);
	    } else {
		    hl2 = 0;
	    }
	    hl3 = 1.7 * 0.00001 * m * (5867 - paValue);
	    hl4 = 0.0014 * m * (34 - taValue);
	    hl5 = 3.96 * fcl * (Math.pow(xn, 4) - Math.pow((tra / 100), 4));
	    hl6 = fcl * hc * (tcl - taValue);
	    ts = 0.303 * Math.exp(-0.036 * m) + 0.028;
	    pwv = ts * (mw - hl1 - hl2 - hl3 - hl4 - hl5 - hl6);
	    ppd = 100 - 95 * Math.exp(-0.03353 * Math.pow(pwv, 4) - 0.2179 * Math.pow(pwv, 2));
   } else {
		    ppd = 100;
		    pwv = 9999;
   }
alert(ppd);
alert(pwv);
}
</script>
I don't know the problem I think every thing is right!
  • 0

#2 BlackRabbit

BlackRabbit

    CodeCall Legend

  • Expert Member
  • PipPipPipPipPipPipPipPip
  • 3871 posts
  • Location:Argentina
  • Programming Language:C, C++, C#, PHP, JavaScript, Transact-SQL, Bash, Others
  • Learning:Java, Others

Posted 12 April 2012 - 06:09 AM

and would the nature of the problem be ?
  • 0

#3 Hamed

Hamed

    CC Devotee

  • Senior Member
  • PipPipPipPipPipPip
  • 413 posts

Posted 12 April 2012 - 09:17 AM

alert(ppd);
alert(pwv);
no action
  • 0

#4 John

John

    CC Mentor

  • Moderator
  • 4450 posts
  • Location:New York, NY

Posted 12 April 2012 - 01:07 PM

Do you ever call the calculate() function on an event?
  • 0

#5 Hamed

Hamed

    CC Devotee

  • Senior Member
  • PipPipPipPipPipPip
  • 413 posts

Posted 13 April 2012 - 04:33 AM

Yes,
I did no answer!
  • 0

#6 John

John

    CC Mentor

  • Moderator
  • 4450 posts
  • Location:New York, NY

Posted 13 April 2012 - 11:15 AM

Look in the JavaScript console.
  • 0

#7 BlackRabbit

BlackRabbit

    CodeCall Legend

  • Expert Member
  • PipPipPipPipPipPipPipPip
  • 3871 posts
  • Location:Argentina
  • Programming Language:C, C++, C#, PHP, JavaScript, Transact-SQL, Bash, Others
  • Learning:Java, Others

Posted 13 April 2012 - 11:22 AM

Hamed,

What about changing this line :
int n = 0, flag = 0;

for this one

var n = 0, flag = 0;

in the other hand i would like to see the whole page, there is also the chance for one of these control to be misspelled or not present in the document, for example :

$("#clo").val();

it might happend that clo is not present in the document, and so the with the other html elements.
  • 0

#8 JackomoLight

JackomoLight

    CC Resident

  • Advanced Member
  • PipPipPipPip
  • 97 posts
  • Programming Language:PHP, Python, JavaScript, PL/SQL
  • Learning:C, Java, C++, Perl, Ruby, Lisp, Bash

Posted 15 April 2012 - 05:15 AM

If you have some kind of pop-up blocker enabled try to disable it.
  • 0





Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download