CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Join Date
    Mar 2007
    Posts
    116

    Lightbulb Javascript Function!!

    Hi Guys...I do not have very good knowledge in Javascript...So please help me out to write a right function...

    Code:
    protected void txtEstimatedContractTotal_TextChanged(object sender, EventArgs e)
            {
                
                if (m_bChangeOccuring)
                    return;
                m_bChangeOccuring = true;
                double dPercent = 0;
                try
                {
                    dPercent = Convert.ToDouble(txtPercentage.Text);
                    txtEstimatedCommission.Text = Convert.ToString(Convert.ToDouble(txtEstimatedContractTotal.Text) * dPercent);
                    txtBalance.Text = Convert.ToString(Convert.ToDouble(txtFinalContractTotal.Text) - Convert.ToDouble(txtDepositReceived.Text) - Convert.ToDouble(txtBalanceReceived.Text));
                }
                catch (Exception ex)
                {
                }
                m_bChangeOccuring = false;
            }
    This is the function which I have written in C# in .cs file...I wanna write the same function in Javascript....so please help me to write this function in Javascript..
    Last edited by PeejAvery; March 2nd, 2009 at 03:40 PM. Reason: Added code tags.

  2. #2
    Join Date
    May 2002
    Posts
    10,943

    Re: Javascript Function!!

    [ redirected thread ]
    If the post was helpful...Rate it! Remember to use [code] or [php] tags.

  3. #3
    Join Date
    May 2002
    Posts
    10,943

    Re: Javascript Function!!

    The text changing event you will have to trigger on the actual text inputs. But, the code below should produce the same results.

    Code:
    function txtEstimatedContractTotal() {
      if (m_bChangeOccuring) {return;}
      m_bChangeOccuring = true;
      double dPercent = 0;
    
      // you will have to make sure that the following elements have IDs
      txtPercentage = document.getElementById('txtPercentage');
      txtEstimatedCommission = document.getElementById('txtEstimatedCommission');
      txtEstimatedContractTotal = document.getElementById('txtEstimatedContractTotal');
      txtBalance = document.getElementById('txtBalance');
      txtDepositReceived = document.getElementById('txtDepositReceived');
      txtBalanceReceived = document.getElementById('txtBalanceReceived');
    
      try {
        dPercent = txtPercentage.value;
        txtEstimatedCommission.value = txtEstimatedContractTotal.value * dPercent;
        txtBalance = txtFinalContractTotal.value - txtDepositReceived.value - txtBalanceReceived.value;
      }
      catch (e) {}
    
      m_bChangeOccuring = false;
    }
    If the post was helpful...Rate it! Remember to use [code] or [php] tags.

  4. #4
    Join Date
    Mar 2007
    Posts
    116

    Thumbs up Re: Javascript Function!!

    Thanks Peej

Posting Permissions

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





Click Here to Expand Forum to Full Width

Featured