Javascript Operation Adding up var values of checked radiabuttons

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Sansasoon
    New Member
    • Feb 2008
    • 2

    Javascript Operation Adding up var values of checked radiabuttons

    Hi there,
    I am supposed to do a shop ... which I ve done so far. The only thing that I can't get working is adding up to get the result

    It would be really great if someone could help me (Sorry it is in GERMAN)
    ThX in advance
    Sansasoon

    [HTML] <html>
    <head>
    <title>Warenkor b berechnen</title>
    <script language="Javas cript">
    <!--
    function fensteropen() {
    var fenster=window. open("fenster.h tml", "zweites", "width=430,heig ht=120,status=y es,toolbar=no") ;
    }
    //--></script>
    </head>
    <body bgcolor="#CC000 0" link="#FFFFFF" vlink="#FFFFFF" alink="#FFFFFF" >
    <div align="center"> <font size="6">Warenk orb berechnen </font></div>
    <div align="center">
    <p><font size="5">Bitte w&auml;hlen Sie aus, welche Pizzen wir Ihnen liefern
    sollen:</font></p>
    <table width="492" cellspacing="5" cellpadding="5" border="1" height="230" bgcolor="#FFAF0 9">
    <form>
    <tr>
    <td width="66">
    <input type="checkbox" value="checkbox ">
    </td>
    <td width="144"><fo nt size="4">Pizza Napoli</font></td>
    <td width="126"><fo nt size="4">&euro; 5,55</font></td>
    <td rowspan="8" width="77"><img src="../bilder/aktion.jpg" width="146" height="200"></td>
    </tr>
    <tr>
    <td width="66">
    <input type="checkbox" value="checkbox ">
    </td>
    <td width="144"><fo nt size="4">Pizza Funghi</font></td>
    <td width="126"><fo nt size="4">&euro; 5,95</font></td>
    </tr>
    <tr>
    <td width="66">
    <input type="checkbox" value="checkbox ">
    </td>
    <td width="144"><fo nt size="4">Pizza-Salami</font></td>
    <td width="126"><fo nt size="4">&euro; 6,15</font></td>
    </tr>
    <tr>
    <td width="66">
    <input type="checkbox" value="checkbox ">
    </td>
    <td width="144"><fo nt size="4">Pizza Calzone</font></td>
    <td width="126"><fo nt size="4">&euro; 7,45</font></td>
    </tr>
    <tr>
    <td width="66">
    <input type="checkbox" value="checkbox ">
    </td>
    <td width="144"><fo nt size="4">Gr&uum l;ner Salat</font></td>
    <td width="126"><fo nt size="4">&euro; 5,05</font></td>
    </tr>
    <tr>
    <td colspan="2"><fo nt size="4">Summe gesamt in &euro;</font></td>
    <td width="126">
    <input type="text" >
    </td>
    </tr>
    <tr>
    <td colspan="2"> <font size="4">
    <input type="button" name="Button" value=" Jetzt berechnen ">
    </font> </td>
    <td width="126">
    <input type="reset" name="Button2" value=" Zur&uuml;ck ">
    </td>
    </tr>
    <tr>
    <td colspan="2">&nb sp;</td>
    <td width="126">&nb sp;</td>
    </tr>
    </form>
    </table>
    <p><font size="5">Aktion swoche: Bestellen Sie drei Aktions-Pizzen zum Preis
    von einer!<br>
    N&auml;here Informationen zu unserem Angebot erhalten Sie</font>
    <a href="#" onClick="fenste ropen()"><font size="5">hier</font></a>.</p>
    </div>
    </body>
    </html>[/HTML]
    Last edited by acoder; Feb 29 '08, 04:24 PM. Reason: Added code tags
  • hsriat
    Recognized Expert Top Contributor
    • Jan 2008
    • 1653

    #2
    German is not a problem, but can you please edit your post and add [html] in the starting and [/html] in the end of your HTML code?

    That helps people out here to find the problem quickly.

    Comment

    • acoder
      Recognized Expert MVP
      • Nov 2006
      • 16032

      #3
      Please enclose your posted code in [code] tags (See How to Ask a Question).

      This makes it easier for our Experts to read and understand it. Failing to do so creates extra work for the moderators, thus wasting resources, otherwise available to answer the members' questions.

      Please use [code] tags in future. Thanks!

      Moderator.

      Comment

      • Sansasoon
        New Member
        • Feb 2008
        • 2

        #4
        Hi,
        how can I edit my Question?
        ThX Sansoon


        Originally posted by acoder
        Please enclose your posted code in [code] tags (See How to Ask a Question).

        This makes it easier for our Experts to read and understand it. Failing to do so creates extra work for the moderators, thus wasting resources, otherwise available to answer the members' questions.

        Please use [code] tags in future. Thanks!

        Moderator.
        Last edited by acoder; Feb 29 '08, 06:28 PM.

        Comment

        • hsriat
          Recognized Expert Top Contributor
          • Jan 2008
          • 1653

          #5
          Unfortunately, there are lots of things missing in your code.

          You may have a look at the following tutorial first:
          If the problem would still persist, we are here to help you out.

          Comment

          • acoder
            Recognized Expert MVP
            • Nov 2006
            • 16032

            #6
            Originally posted by Sansasoon
            Hi,
            how can I edit my Question?
            ThX Sansoon
            Don't worry, I've added the code tags for you. Just remember to use them next time you post code.

            As for your question, you need to access the numbers in some way. I assume that you want to total the items for which the checkboxes are checked. The best thing to do in this situation is to set the value of each checkbox to the number it represents. Then get each checked checkbox and add the numbers up.

            To get all the checkboxes, use document.getEle mentsByTagName( "input"). Then loop over the checkboxes and check that they are checked. If so, add to the total.

            Comment

            Working...