Results 1 to 2 of 2

Thread: calculator

  1. #1

    Thread Starter
    Fanatic Member merhaba's Avatar
    Join Date
    Sep 2002
    Location
    Istanbul,Bartin-Gallipoli(Gelibolu-Canakkale)
    Posts
    601

    calculator

    hi there,
    could you please help me in creating a simple calculator..just to get an idea of how "a text box" is used to input numbers..!!!
    thanks

  2. #2
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170
    Code:
    
    <HEAD>
    
    <SCRIPT LANGUAGE="JavaScript">
    
    
    <!-- Begin
    function a_plus_b(form) {
    a=eval(form.a.value)
    b=eval(form.b.value)
    c=a+b
    form.ans.value = c
    }
    function a_minus_b(form) {
    a=eval(form.a.value)
    b=eval(form.b.value)
    c=a-b
    form.ans.value=c
    }
    function a_times_b(form) {
    a=eval(form.a.value)
    b=eval(form.b.value)
    c=a*b
    form.ans.value=c
    }
    function a_div_b(form) {
    a=eval(form.a.value)
    b=eval(form.b.value)
    c=a/b
    form.ans.value = c
    }
    function a_pow_b(form) {
    a=eval(form.a.value)
    b=eval(form.b.value)
    c=Math.pow(a, b)
    form.ans.value = c
    }
    // End -->
    </SCRIPT>
    
    
    <BODY>
    <CENTER>
    <FORM name="formx"><input type=text size=4 value=12 name="a"> 
    <input type="button" value="  +  " onClick="a_plus_b(this.form)">  
    <input type="button" value="  -  " onClick="a_minus_b(this.form)">  
    <input type="button" value="  x  " onClick="a_times_b(this.form)">  
    <input type="button" value="  /  " onClick="a_div_b(this.form)">  
    <input type="button" value="  ^  " onClick="a_pow_b(this.form)">  
    <input type="number" size=4 value=3 name="b"> = <input type "number" value=0 name="ans" size=9>
    </FORM>
    </CENTER>

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