It appears you have not yet registered with DEVPPL. To register please click here... (it's fast, easy and free!)

Forum

Log In Sponsors
Board index Programming JavaScript Forum

displaying javascript results in a text box

displaying javascript results in a text box

Postby slowbob on Tue Nov 02, 2010 6:12 am

I'm trying to get each of the if statements below in a text text box with the result depending on the answer of the equation. However i can't figure out a way to allow the user to click a button to to show the result in a text box. If anyone could help it would be much appreciated.

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<TITLE> New Document </TITLE>
<script type="text/javascript">
function calculate() {

A = document.form1.text2.value

B =(parseInt(A ) * 52)

D= (parseInt(B ) * 0.015 )

if ( B <= 6000){
tax = 0;}

else

if (B <= 37001){

tax = (B - 6000) * .15;

}
else

if (B<= 80001){

tax = (B - 37000) * .30 + (37000 - 6000) * .15;

}
else

if (B <= 180001){

tax = (B- 80000) * .37 + (80000- 37000) * .30 + (37000 - 6000) * .15;

}
else

tax = (B - 180000)* .45 + (180000 - 80000) * .37 + (80000- 37000) * .30 + (37000 - 6000) * .15;}



</script>
</HEAD>

<BODY>
<form name="form1">
Weekly Salary: <INPUT TYPE="TEXT" NAME="text2">
<INPUT TYPE="BUTTON" VALUE="SUBMIT" Onclick="calculate();">

</BODY>
</HTML>
slowbob
 
Posts: 1
Joined: Tue Nov 02, 2010 5:55 am

Re: displaying javascript results in a text box

Postby HotNoob on Tue Nov 02, 2010 3:10 pm

easy as pie :)


Code: Select all
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
    <HEAD>
        <TITLE> New Document </TITLE>
            <script type="text/javascript">
            function calculate()
            {
                A = document.getElementById('input').value;
                outDiv = document.getElementById('output');
                B =(parseInt(A) * 52);
                //alert(A);
                D = (parseInt(B) * 0.015 );
               
                if ( B <= 6000)
                {
                    tax = 0;
                }
                else if (B <= 37001)
                {
                    tax = (B - 6000) * .15;
                }
                else if (B<= 80001)
                {
                    tax = (B - 37000) * .30 + (37000 - 6000) * .15;
                }
                else if (B <= 180001)
                {
                    tax = (B- 80000) * .37 + (80000- 37000) * .30 + (37000 - 6000) * .15;
                }
                else
                {
                    tax = (B - 180000)* .45 + (180000 - 80000) * .37 + (80000- 37000) * .30 + (37000 - 6000) * .15;
                }
                outDiv.innerHTML = '$'+tax;
            }
           
            </script>
    </HEAD>
<BODY>
    Weekly Salary: <INPUT TYPE="TEXT" id='input' NAME="text2" />
    <INPUT TYPE="BUTTON" VALUE="SUBMIT" onClick="calculate();" />
    <div id='output'> </div>
</BODY>
</HTML>

tudahhh!
HotNoob
100+ Club
 
Posts: 169
Joined: Sun May 02, 2010 1:38 am


Who is online

Users browsing this forum: No registered users and 4 guests