[nfbcs] trying to make a smart page

Stanzel, Susan - FSA, Kansas City, MO Susan.Stanzel at kcc.usda.gov
Thu Jan 15 14:56:22 UTC 2015


Good morning Listers,

I am sending this to both lists. I have been asked to try to get this working. They want to add numbers together keeping track of the running total. I am using Windows7, IE9, and JAWS 15. Any assistance will be greatly appreciated. It works better in FireFox, but our default browser is IE. I know how to read HTML and JavaScript, but I am not very knowledgible on writing it. The code follows my name.

Susie

<!DOCTYPE  html>
<html>
       <head>
              <title>Output test</title>
       </head>
       <body>
              <form method="post" action="#">
                     <label for="input1Id">Input 1:</label>
                     <input id="input1Id" aria-controls="outputId" type="text">
                     <br>
                     <label for="input2Id">Input 2:</label>
                     <input id="input2Id" type="text" aria-controls="outputId" >
                     <br>
                     <label for="input3Id">Input 3:</label>
                     <input id="input3Id" type="text" aria-controls="outputId">
                     <hr>
                     <div aria-live="polite" aria-atomic="true" role="region"
aria-labelledby="Result">

                     <span id="sumLabel">Sum: </span>
                     <span id="outputId" >
                     </span>
                     </div>
              </form>
              <script type="text/javascript">
                     var inputIds = ["input1Id", "input2Id", "input3Id"];
                     function handleBlur()
                     {
                           var output = document.getElementById("outputId");
                           var sum = 0;
                           for (var i = 0; i < inputIds.length; i++)
                           {
                                  var inputId = inputIds[i];
                                  var input = document.getElementById(inputId);
                                  var value = parseInt(input.value, 10);
                                  if (! isNaN(value))
                                  {
                                         sum += value;
                                  }
                           }
                           output.removeChild(output.firstChild);
                           var text = document.createTextNode(sum);
                           output.appendChild(text);
                     }



                     var inputs = document.getElementsByTagName("input");
                     for (var i = 0; i < inputs.length; i++)
                     {
                           inputs[i].addEventListener("blur", handleBlur);

                     }
                     document.getElementById("input1Id").focus();
              </script>
</html




This electronic message contains information generated by the USDA solely for the intended recipients. Any unauthorized interception of this message or the use or disclosure of the information it contains may violate the law and subject the violator to civil or criminal penalties. If you believe you have received this message in error, please notify the sender and delete the email immediately.



More information about the NFBCS mailing list