Javasript onblur,onfocus giving problem

Results 1 to 2 of 2

Thread: Javasript onblur,onfocus giving problem

  1. #1
    Join Date
    Dec 1969

    Default Javasript onblur,onfocus giving problem

    Here is my function which I am calling from onblur and onfocus of the textboxes.<BR>var bflag=0;<BR>function Check()<BR>{<BR> var str1 = document.MyForm.fy1bshcFH.value;<BR> var str2 = document.MyForm.fy1bsfundFH.value;<BR> var str3 = document.MyForm.fy1pshcFH.value;<BR> var str4 = document.MyForm.fy1psfundFH.value;<BR> var str5 = document.MyForm.fy1bshcSH.value;<BR> var str6 = document.MyForm.fy1bsfundSH.value;<BR> var str7 = document.MyForm.fy1pshcSH.value;<BR> var str8 = document.MyForm.fy1psfundSH.value;<BR><BR><BR> if(parseInt(str1) &#062;= 0 && parseInt(str2) &#062;= 0 && parseInt(str3) &#062;= 0 && parseInt(str4) &#062;= 0 && parseInt(str5) &#062;= 0 && parseInt(str6) &#062;= 0 && parseInt(str7) &#062;= 0 && parseInt(str8) &#062;= 0)<BR> {<BR> str9=eval(str1)+eval(str3);<BR> str10=eval(str2)+eval(str4);<BR> str11=eval(str5)+eval(str7);<BR> str12=eval(str6)+eval(str8);<BR> str13 =eval(str2)/2;<BR> <BR> if(str13 &#062;=0)<BR> {<BR> document.MyForm.fy1bsfundSH.value=str13;<BR> document.MyForm.fy1bsfundFH.value=str13<BR> } <BR> <BR> <BR> if(str9 &#062;=0)<BR> {<BR> document.MyForm.fy1tothcFH.value=str9;<BR> }<BR> if(str10 &#062;=0)<BR> {<BR> document.MyForm.fy1totfundFH.value=str10;<BR> }<BR> if(str11 &#062;=0)<BR> {<BR> document.MyForm.fy1tothcSH.value=str11;<BR> }<BR> if(str12 &#062;=0)<BR> {<BR> document.MyForm.fy1totfundSH.value=str12;<BR> }<BR> <BR> <BR> <BR><BR> }<BR> else<BR> {<BR> if(parseInt(str1) &#062;=0)<BR> {<BR> document.MyForm.fy1pshcFH.value=0;<BR> document.MyForm.fy1psfundFH.value=parseInt(str1);< BR> }<BR> if(parseInt(str2) &#062;=0)<BR> {<BR> document.MyForm.fy1tothcFH.value=0;<BR> document.MyForm.fy1totfundFH.value=parseInt(str2); <BR> }<BR> if(parseInt(str5) &#062;=0)<BR> {<BR> document.MyForm.fy1pshcSH.value=0;<BR> document.MyForm.fy1psfundSH.value=parseInt(str5);< BR> }<BR> if(parseInt(str6) &#062;=0)<BR> {<BR> document.MyForm.fy1tothcSH.value=0;<BR> document.MyForm.fy1totfundSH.value=parseInt(str6); <BR> }<BR> <BR> <BR> else<BR> {<BR> document.MyForm.fy1bshcFH.value=0;<BR> document.MyForm.fy1bshcSH.value=0;<BR> document.MyForm.fy1bsfundFH.value=0;<BR> document.MyForm.fy1bsfundSH.value=0;<BR> document.MyForm.fy1pshcFH.value=0;<BR> document.MyForm.fy1pshcSH.value=0;<BR> document.MyForm.fy1psfundFH.value=0;<BR> document.MyForm.fy1psfundSH.value=0;<BR> document.MyForm.fy1tothcFH.value=0;<BR> document.MyForm.fy1tothcSH.value=0;<BR> document.MyForm.fy1totfundFH.value=0;<BR> document.MyForm.fy1totfundSH.value=0;<BR> }<BR> }<BR>} <BR><BR><BR>Here I am dividing one value and taking that value to another text box. when I go to that text box again..its dividing the value again and again..How to stop this one..I want to divide that only once

  2. #2
    Join Date
    Dec 1969

    Default If you are calling from onBlur()...

    ... *AND* from onFocuse() then OF COURSE that code is going to get called *TWICE* for every time you move to any such field.<BR><BR>If you only want it to happen once, then only call the code from one place, one time.<BR><BR>******<BR><BR>And I can&#039;t help but feel the code itself has problems.<BR><BR>As you have it written, if the value of and field is less than zero *and* if the value of str6 is less than zero then you ignore all the other IF tests and set the values of all the various fields to zero. Do you *really* mean to do that???<BR><BR>

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts