Results 1 to 2 of 2
  1. #1
    henkiej is offline Member
    Join Date
    May 2010
    Posts
    1
    Rep Power
    0

    Default count id's using js.

    I have made a simple script that uses checkboxes and textareas.
    costumers can type a number in the textarea.
    the value of the checkbox is multiplied with the number entered in the textarea.
    The outcome is given at 'prijsbepaling' on the bottom,

    there is only one problem..
    the 'id:total' also at the bottom of the script only counts the value of the checked checkboxes, and not the multiplied outcome..

    does anybody know how it would be possible to count
    calzone
    middel
    groot
    and display it in 'id: total' ?

    Thnx!

    Java Code:
    if(!document.getElementById && document.all) 
    		document.getElementById = function(id){ return document.all[id]} 
    
    var calzone = 0;
    var middel = 0;
    var groot = 0; 
    var total = 0;
    function update(checkbox){
        if(checkbox.checked){
            total += parseFloat(checkbox.value);
        } else {
            total -= parseFloat(checkbox.value);
        };
        document.getElementById("total").innerHTML = "€ " + total.toFixed(2).replace(".", ",");
    };
    
    	<!-- functie voor het verbergen van een element -->
    
    	function showHide (id) 
    	{ 
    	var style = document.getElementById(id).style 
    	if (style.visibility == "hidden") 
    	style.visibility = "visible"; 
    	else 
    	style.visibility = "hidden"; 
    	} 
    	<!-- vermenigvuldigen --> 
    		
    	function multiply(value, multiplier, outputId) { 
    	document.getElementById(outputId).innerHTML = "€ " + value * multiplier + ",-";
    
    }
    XML Code:
    <tr><td><input type="checkbox" value="3" onclick="showHide('calzone1');update(this);"></input></td><td>€ 3,00</td>
    <td>
    <div id="calzone1" style="visibility: hidden;"> 
    <input name="hoeveelheid" type="text" onkeyup="multiply(this.value, 3, 'calzone')" id="hoeveelheid" size="2" maxlength="2">
    <label for="hoeveelheid">Maal</label></div>
    </td></tr>
    
    <tr><td><input type="checkbox" value="4.00" onclick="showHide('middel1');update(this);"></input></td><td>€ 4,00</td>
    <td>
    <div id="middel1" style="visibility: hidden;"> 
    <input name="hoeveelheid" type="text" onkeyup="multiply(this.value, 4, 'middel')" id="hoeveelheid" size="2" maxlength="2">
    <label for="hoeveelheid">Maal</label></div>
    </td></tr>
    
    <tr><td><input type="checkbox" value="5.00" onclick="showHide('groot1');update(this);"></input></td><td>€ 5,00</td>
    <td>
    <div id="groot1" style="visibility: hidden;"> 
    <input name="hoeveelheid" type="text" onkeyup="multiply(this.value, 5, 'groot')" id="hoeveelheid" size="2" maxlength="2">
    <label for="hoeveelheid">Maal</label></div>
    </td></tr>
    
    <!-- prijsbepaling -->
    
    <tr><td></td><td><b>Calzone:</b></td><td id="calzone">€ 0,00</td></tr>
    <tr><td></td><td><b>Middel:</b></td><td id="middel">€ 0,00</td></tr> 
    <tr><td></td><td><b>Groot:</b></td><td id="groot">€ 0,00</td></tr>
    <tr><td></td><td><b>Totaal:</b></td><td id="total">€ 0,00</td></tr>

  2. #2
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,529
    Blog Entries
    7
    Rep Power
    20

    Default

    This is a Java forum; your question is about JavaScript; both languages don't have much in common, sorry.

    kind regards,

    Jos

Similar Threads

  1. how to count the given character?
    By ashin in forum Advanced Java
    Replies: 1
    Last Post: 10-14-2009, 04:28 PM
  2. to get count value as a variable
    By arunkumarinfo in forum JDBC
    Replies: 2
    Last Post: 03-30-2009, 01:32 AM
  3. Making a count..
    By Samgetsmoney in forum New To Java
    Replies: 15
    Last Post: 02-18-2009, 01:44 PM
  4. Getting row count
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 02-11-2008, 08:49 AM
  5. How to get Id's alone
    By peiceonly in forum Lucene
    Replies: 1
    Last Post: 08-07-2007, 05:45 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •