calculation function

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Dormilich
    Recognized Expert Expert
    • Aug 2008
    • 8694

    #16
    there are still typing mistakes...
    Code:
    function calculate() [b]{[/b]   // line 2
    for ([b]var[/b] i = 0; i < cams.length; i++) {   // line 16
    document.getElementsByName("grade")[b][0][/b].value = grade;   // line 71

    Comment

    • acoder
      Recognized Expert MVP
      • Nov 2006
      • 16032

      #17
      Originally posted by acoder
      No, document.getEle mentByName("cam ") returns an array of elements, so something like:
      [code=javascript]var cams = document.getEle mentByName("cam ");
      var finals = document.getEle mentByName("fin al_exam");
      var total = 0;
      for (i = 0; i < cams.length; i++) {
      var total += parseInt(cams[i].value) + parseInt(finals[i].value);
      }
      document.getEle mentByName("tot al").value = total;[/code]
      Gah! What a mess. Serves me right for just copying/modifying code without checking and testing. The last line should be using document.getEle mentById() too.

      Comment

      • azura
        New Member
        • Jul 2008
        • 47

        #18
        i'm sory sir...

        actually all the record are from my database.... that's why i use repeat region.. once admin find record by search all the data that require display.. but cam,final,are marks to be insert by admin..once admin key in the marks, total and gred will display then the admin save into the database....

        Comment

        • acoder
          Recognized Expert MVP
          • Nov 2006
          • 16032

          #19
          Have you made the corrections as suggested by Dormilich above?

          Comment

          • azura
            New Member
            • Jul 2008
            • 47

            #20
            yup.... i also had some new coding it's work..but the value had been set..how to retrive data from database? let say if had 30 data in database?

            Comment

            • Dormilich
              Recognized Expert Expert
              • Aug 2008
              • 8694

              #21
              You can't do that with javascript alone. You need a server side script language, that can query the database for you. Once you got that working, you can retrieve those data with ajax.

              regards

              Comment

              • azura
                New Member
                • Jul 2008
                • 47

                #22
                must do the ajax also??....can you point me to any source that i can learn about retrieve many data using ajax?? thanks

                Comment

                • Dormilich
                  Recognized Expert Expert
                  • Aug 2008
                  • 8694

                  #23
                  Originally posted by azura
                  must do the ajax also??
                  No. if you query the database before you send the html you certainly don't need ajax. ajax is needed, if you wan't things done 'on the fly' (after page load). but ajax is able to import data directly into javascript.

                  Well, all that depends also on what data you pull from the database and what you want to do with it (I couldn't figure that one out, sorry)

                  regards

                  Comment

                  Working...