dcsimg
www.webdeveloper.com
Results 1 to 4 of 4

Thread: second function not firing from onkeypress event for input

  1. #1
    Join Date
    Mar 2006
    Posts
    157

    second function not firing from onkeypress event for input

    Hello,

    I am trying to add a second function to my input, but the second function isn't working properly. The first function numbersonly() works perfectly. The second function calculate() loads, but always passes the previous value of the input. So when I type in 1000 into the input, it is only passing 100 to the input. When I type 10000, it passes only 1000 to the input. If I put the second function to a button it works perfectly.

    Here is the input:
    HTML Code:
    <INPUT TYPE="TEXT" ID="Points_Field_Left" SIZE="14" onKeyPress="return numbersonly(this, event), calculate(document.getElementById('What_Will_My_Points_Equal_When_Transferred').value, document.getElementById('Points_Field_Left').value, document.getElementById('Resulting_Container_Left').children)">   <INPUT TYPE="BUTTON" ID="Calculate_Button_Left" VALUE="Calculate" onclick="calculate(document.getElementById('What_Will_My_Points_Equal_When_Transferred').value, document.getElementById('Points_Field_Left').value, document.getElementById('Resulting_Container_Left').children)"/>
    Here is the first function:

    Code:
    function revealer(choice, Steps, Instructions, Form_Group)
    {
    	
    	Form_Children = Form_Group.children
    
    	// Hides and Reveals Step # and Text
    
    	for (i = 0; i < 3; i++)
    	{
    
    		Steps[i].style.display = "none";
    		Instructions[i].style.display = "none";
    
    	}
    
    	
    	Steps[choice].style.display = "block";
    	Instructions[choice].style.display = "block";
    
    	if(choice == 0)
    	{
    		
    		Form_Children[1].style.visibility = "hidden";
    		Form_Children[2].style.visibility = "hidden";
    
    	}
    	else
    	{
    		Form_Children[1].style.visibility = "visible";
    		Form_Children[2].style.visibility = "visible";
    	}
    
    }
    Here is the second function:

    [code]
    function calculate(choice, points, output)
    {

    for (i = 0; i < output.length; i++)
    {

    output[i].style.display = "none"

    }


    if(choice == "SPG%2
    Last edited by jedaisoul; 07-27-2016 at 03:43 AM.

  2. #2
    Join Date
    Dec 2002
    Location
    Calgary, Canada
    Posts
    6,144
    instead of keypress, try using keyup event
    Cheers

    Khalid

    Message Posting Guidelines In These Forums, Please read these before posting any question.
    Web site: webapplikations.com
    Web Resources Page:Web Resources

  3. #3
    Join Date
    Oct 2013
    Location
    Sheboygan, Wisconsin
    Posts
    1,559
    Please use code tags. Makes for easier reading.
    http://www.webdeveloper.com/forum/misc.php?do=bbcode

  4. #4
    Join Date
    Mar 2006
    Posts
    157
    The second function is working now, but the first function that prevents any letters from being typed is not working now

    Code:
    function revealer(choice, Steps, Instructions, Form_Group)
     {
    
     Form_Children = Form_Group.children
    
     // Hides and Reveals Step # and Text
    
     for (i = 0; i < 3; i++)
     {
    
     Steps[i].style.display = "none";
     Instructions[i].style.display = "none";
    
     }
    
    
     Steps[choice].style.display = "block";
     Instructions[choice].style.display = "block";
    
     if(choice == 0)
     {
    
     Form_Children[1].style.visibility = "hidden";
     Form_Children[2].style.visibility = "hidden";
    
     }
     else
     {
     Form_Children[1].style.visibility = "visible";
     Form_Children[2].style.visibility = "visible";
     }
    
     }

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles