Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

CF JavaScript problem

Status
Not open for further replies.

calista

Programmer
Jan 24, 2001
545
US
I posted this problem in the JavaScript forum, but based on the responses I got, I am suspicious the problem is with CF, not the JavaScript. What is supposed to happen is, the total should update dynamically as the user enters numbers. When I try it, the total is double what it should be. The alert window (which is in there for debugging purposes at this point) pops up twice. The first time, it shows the correct total, the second time, the total is doubled. This makes me think the script is executing twice. Here is the code that the person who responded to my post said worked for him, but it does not work for me. I even copied his code onto a blank document. Any ideas or suggestions greatly appreciated.
Code:
 <!DOCTYPE HTML PUBLIC &quot;-//W3C//DTD HTML 4.0 Transitional//EN&quot;>

<HTML>
<HEAD>
    <TITLE>Test Four</TITLE>
    <SCRIPT>
<!--
function calculate(which)
    {
        MyTotal=parseInt(document.MyForm.TotalRegHours.value) +  parseInt(which.value);
        alert(MyTotal);
        document.MyForm.TotalRegHours.value = MyTotal;
    }
//-->
</SCRIPT>
</HEAD>

<BODY>

<CFPARAM NAME = TotalRegHours DEFAULT=&quot;0&quot;>
<CFSET RegHours = &quot;0&quot;>

<CFOUTPUT>
<FORM ACTION=&quot;#CGI.SCRIPT_NAME#&quot; METHOD=&quot;post&quot; NAME=&quot;MyForm&quot; ID=&quot;MyForm&quot;>
    <CFLOOP INDEX=&quot;IdxOne&quot; FROM=&quot;1&quot; TO=&quot;5&quot; STEP=&quot;1&quot;>
        <INPUT TYPE=&quot;text&quot; NAME=&quot;RegHours#IdxOne#&quot; CLASS=&quot;WhiteTextBox&quot; VALUE=&quot;#RegHours#&quot; SIZE=&quot;13&quot; ONBLUR=&quot;calculate(this)&quot;><BR>
    </CFLOOP>
    <BR>
    <INPUT TYPE=&quot;text&quot; NAME=&quot;TotalRegHours&quot; CLASS=&quot;BlueTextBox&quot; VALUE=&quot;0&quot; READONLY SIZE=&quot;13&quot;>
</FORM>
</CFOUTPUT>
<BR>
</BODY>
</HTML>
Calista :-X
Jedi Knight,
Champion of the Force
 
OK, it was JavaScript. I found out in the Javascript forum that ONBLUR is very sensitive to double clicking, and other human intervention. I was using the tab key to advance to the next field, and it was running the script twice. I changed ONBLUR to ONCHANGE, and now it works fine. Calista :-X
Jedi Knight,
Champion of the Force
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top