[nfbcs] More help with javascript calculater

Nicole Torcolini ntorcolini at wavecable.com
Fri Nov 25 04:14:06 UTC 2016


The problem is that your button does not know which function to perform. You need to have a separate function for your button that checks which option is selected and then calls the associated function.

-----Original Message-----
From: nfbcs [mailto:nfbcs-bounces at nfbnet.org] On Behalf Of Taylor Arndt via nfbcs
Sent: Thursday, November 24, 2016 6:30 PM
To: NFB in Computer Science Mailing List
Cc: Taylor Arndt
Subject: [nfbcs] More help with javascript calculater

Hi,
So i got some of my calculater

--
 Taylor

 to work, but it seems like subtraction is the only thing it wants to do now, and i want to implament all 4 functions Here is the code:
<!DOCTYPE html
 PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
        <head>
                <title>Accessible calculator</title>

                <script>
 function function_calculate(){
 }
function function_add()
 {
  var first_number=parseFloat(document.getElementById('Text1').value);
                                var
second_number=parseFloat(document.getElementById('Text2').value);
           var myResult=(first_number+second_number);
document.getElementById('txtresult').innerHTML = myResult; }

function function_subtract()
 {
  var first_number=parseFloat(document.getElementById('Text1').value);
                                var
second_number=parseFloat(document.getElementById('Text2').value);
           var myResult=(first_number-second_number);
document.getElementById('txtresult').innerHTML = myResult; }

                </script>
       </head>

       <body>
                <p>
<br/>
                        <label for"first number">Enter the first
number: </label>
                        <input type="text" title="Enter first number:"
label="first number" name="first number" id="Text1" /><br/>
                        <label for"operation">Choose operation: </label> <select>
       <option>Add</option>	
                <option>Subtract</option> <option>Multiply</option> <option>Divide</option> </select>

<br/>  <label for"2nd number">Enter the second number: </label>
                        <input type="text" title="2nd number" id="Text2"/><br/>
        <button type="button" title="calculate" name="calculate"
onclick=" function_calculate();  function_add(); function_subtract(); function_multiply(); function_divide(); "/>Calculate</button>
                </p>
                <p  style="font-size: xx-large; font-weight:
bolder;">result: <span id="txtresult"></span></p> </body> </html>

Thanks for all the help, and i apreciat it

_______________________________________________
nfbcs mailing list
nfbcs at nfbnet.org
http://nfbnet.org/mailman/listinfo/nfbcs_nfbnet.org
To unsubscribe, change your list options or get your account info for nfbcs:
http://nfbnet.org/mailman/options/nfbcs_nfbnet.org/ntorcolini%40wavecable.com





More information about the NFBCS mailing list