www.webdeveloper.com
Recent Articles
  • Finding Slow Running Queries in ASE 15
  • A More Advanced Pie Chart for Analysis Services Data
  • Adobe AIR Programming Unleashed: Working with Windows
  • Performance Testing SQL Server 2008's Change Data Capture Functionality
  • The ABC's of PHP: Introduction to PHP
  • How to Migrate from BasicFiles to SecureFiles Storage
  • Why the Twitter Haters Are Wrong
  • User Personalization with PHP: Beginning the Application
  • Whats in an Oracle Schema?
  • Lighting Enhancement in Photoshop
  •  

    Go Back   WebDeveloper.com > Client-Side Development > JavaScript

    JavaScript JavaScript (not Java) Discussion and technical support, including AJAX and frameworks (JQuery, MooTools, Prototype...)

    Reply
     
    Thread Tools Search this Thread Rate Thread Display Modes
      #1  
    Old 07-19-2006, 05:55 AM
    renevanh renevanh is offline
    Registered User
     
    Join Date: Dec 2004
    Location: The Netherlands
    Posts: 86
    problems with calculation

    I'm creating a form which user can use to order some dvd's. It should be rewritten once in PHP, but that's not important. All I want now is the form to function so I can use a mailscript from my ISP to send the neccesary data.
    The problem is the script won't work the right way yet: calculation of the total price (t) isn't working the way I want it.
    When I check one of the checkboxes, the value is displayed in the "totaal" field, but when I check another, the value is replaced and not added as needed.
    Can anyone tell me where my mistake lies?
    (Might be something with strings/values...)
    I placed the entire script so anyone can test it and see the problem.
    (Tested with Firefox)

    René

    Code:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
       "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head>
    <title></title>
    <link rel="stylesheet" type="text/css" href="../scripts/style.css">
    
    <script language="Javascript">
    <!--
    
    function prijs()
    {
    
    Keukenhof = false;
    Volendam = false;
    Windmolen = false;
    Grand_tour = false;
    Citytour = false;
    None = true;
    
    
    a = "";
    b = "";
    c = "";
    d = "";
    e = "";
    
      if (window.document.bestel.Keukenhof.checked == true) {
        Keukenhof = true;
      }
      else {
        if (window.document.bestel.Volendam.checked == true) {
        Volendam = true;
        }
        else {
          if (window.document.bestel.Windmolentour.checked == true) {
          Windmolen = true;
          }
          else {
            if (window.document.bestel.Grand_Tour_Holland.checked == true) {
            Grand_tour = true;
            }
            else {
              if (window.document.bestel.Citytour.checked == true) {
              Citytour = true;
              }
            }
          }
        }
      }
    
    
      if (Keukenhof == true) {
        a = window.document.bestel.Keukenhof.value;
      }
      else  {
        if (Volendam == true) {
          b = window.document.bestel.Volendam.value; 
        }
        else {
          if (Windmolen == true) {
            c = window.document.bestel.Windmolentour.value;
          }
          else { 
            if (Grand_tour == true) {
              d = window.document.bestel.Grand_Tour_Holland.value;
            }
            else {
              if (Citytour == true) {
                e = window.document.bestel.Citytour.value;
              }
              else {
                t = 0,00;
              }
            }
          }
        }
      }
      
    t = a + b + c + d + e;
    window.document.bestel.totaal.value = t;
    
        
    }
    //-->
    </script>
    </head>
    <body>
    <center><p class="header">Bestelformulier</center>
    <br><br>
    <p class="text">Door middel van onderstaand formulier kunt u de door u gewenste producten bestellen.<br>
    Het formulier bevat drie onderdelen: naw gegevens, de bestelling en de betalingsgegevens.<br>
    Uw gegevens worden niet aan derde gegeven of doorverkocht.
    <br><br>
    <form name="bestel">
    <p class="form">
    Deel 1: Naam, Adres en Woonplaatsgegevens.<br><br>
    Voornaam/Voorletter(s): <input type="text" name="voornaam" value=""><br>
    Achternaam: <input type="text" name="achternaam" value=""><br>
    Straatnaam: <input type="text" name="Straat" value=""> Huisnummer: <input type="text" name="nummer" value=""><br>
    Postcode: <input type="text" name="Postcode" value=""> Woonplaats: <input type="text" name="Woonplaats" value="">
    <br><br>
    Deel 2: De bestelling<br>
    Vink aan welke producten u graag ontvangt.<br><br>
    <input type="checkbox" name="Keukenhof" value=19,95 onChange="prijs()"> De Keukenhof<br>
    <input type="checkbox" name="Volendam" value=14,95 onChange="prijs()"> Volendam<br>
    <input type="checkbox" name="Windmolentour" value=19,95 onChange="prijs()"> Windmolentour<br>
    <input type="checkbox" name="Grand_Tour_Holland" value=19,95 onChange="prijs()"> Grand Tour Holland<br>
    <input type="checkbox" name="Citytour" value=14,95 onChange="prijs()"> Citytour<br>
    <br>
    <br>
    <input type="textbox" name = "totaal" value="0,00">
    </form>
    </body>
    </html>
    __________________
    Don't take life to serious, you won't survive it anyway...
    Reply With Quote
      #2  
    Old 07-19-2006, 07:04 AM
    96turnerri's Avatar
    96turnerri 96turnerri is offline
    L.A.M.P.
     
    Join Date: Sep 2003
    Location: Portsmouth, UK Occupation: Web Developer
    Posts: 2,658
    you if / else / if / else .................. if / elss x 20 is borked, since it will only ever do one of a, b, c, d......

    Code:
    if (Keukenhof == true) {
      a = window.document.bestel.Keukenhof.value;
    }
    if (Volendam == true) {
      b = window.document.bestel.Volendam.value; 
    }
    if (Windmolen == true) {
      c = window.document.bestel.Windmolentour.value;
    }
    if (Grand_tour == true) {
      d = window.document.bestel.Grand_Tour_Holland.value;
    }
    if (Citytour == true) {
      e = window.document.bestel.Citytour.value;
    }
    Code:
      if (Keukenhof == true) {
        a = window.document.bestel.Keukenhof.value;
      }
      else  {
        if (Volendam == true) {
          b = window.document.bestel.Volendam.value; 
        }
        else {
          if (Windmolen == true) {
            c = window.document.bestel.Windmolentour.value;
          }
          else { 
            if (Grand_tour == true) {
              d = window.document.bestel.Grand_Tour_Holland.value;
            }
            else {
              if (Citytour == true) {
                e = window.document.bestel.Citytour.value;
              }
              else {
                t = 0,00;
              }
            }
          }
        }
      }
    __________________
    Richard Turner - A Virtual Insight
    Reply With Quote
      #3  
    Old 07-19-2006, 08:20 AM
    renevanh renevanh is offline
    Registered User
     
    Join Date: Dec 2004
    Location: The Netherlands
    Posts: 86
    Right... stupid me

    Thanks for the hint.

    René
    __________________
    Don't take life to serious, you won't survive it anyway...
    Reply With Quote
      #4  
    Old 07-19-2006, 09:13 AM
    James Gatka James Gatka is offline
    Banned
     
    Join Date: Jan 2006
    Location: I'm in GMT -5
    Posts: 561
    Rene:

    Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
       "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <script type="text/javascript">
    
    	function prijs(nBox){
    
    		var currTotaal = Number(document.forms[0]['totaal'].value.replace(",","."));
    		if (nBox.checked)
    			{
    			 document.forms[0]['totaal'].value = ((currTotaal + Number(nBox.value)).toFixed(2)).replace(".",",");
    			}
    		else 	{
    		 	 document.forms[0]['totaal'].value = ((currTotaal - Number(nBox.value)).toFixed(2)).replace(".",",");
    			}
    	}
    
    </script>
    <style type="text/css">
    
    	form {width:420px;margin:auto}
    	fieldset {padding:5px;background-color:#f0fff0;}
    	legend {font-size:14pt;color:#00008b;background-color:#afeeee;padding:3px;margin:10px;font-family:arial}
    	label {font-size:12pt;margin:5px}
    
    </style>
    
    </head>
    	<body>
    		<form>
    			<fieldset>
    				<legend> Bestelformulier </legend>
    				<label> Deel 1: Naam, Adres en Woonplaatsgegevens.</label>
    				<br><br>
    				<label> Voornaam/Voorletter(s): <input type="text" name="voornaam" size="15"></label>
    				<br>
    				<label> Achternaam: <input type="text" name="achternaam" size="20"></label>
    				<br>
    				<label> Straatnaam: <input type="text" name="Straat" size="20"></label> <label>Huisnummer: <input type="text" name="nummer" size="6"></label>
    				<label> Postcode: <input type="text" name="Postcode" size="6"></label> <label> Woonplaats: <input type="text" name="Woonplaats" size="20"></label>
    				<br><br>
    				<label>Deel 2: De bestelling </label>
    				<br>
    				<label> Vink aan welke producten u graag ontvangt.</label>
    				<br><br>
    				<label><input type="checkbox" name="Keukenhof" value="19.95" onclick="prijs(this)"> De Keukenhof </label>
    				<br>
    				<label><input type="checkbox" name="Volendam" value="14.95" onclick="prijs(this)"> Volendam </label>
    				<br>
    				<label><input type="checkbox" name="Windmolentour" value="19.95" onclick="prijs(this)"> Windmolentour </label>
    				<br>
    				<label><input type="checkbox" name="Grand_Tour_Holland" value="19.95" onclick="prijs(this)"> Grand Tour Holland </label>
    				<br>
    				<label><input type="checkbox" name="Citytour" value="14.95" onclick="prijs(this)"> Citytour </label>
    				<br><br>
    				<label><input type="textbox" name="totaal" value="0,00" size="6" readonly> Totaal </label>
    					<div style='text-align:center;padding-top:5px'>
    						<button type='submit'> Submit </button>
    					</div>
    			</fieldset>
    		</form>
    
    	</body>
    </html>

    Last edited by James Gatka; 07-19-2006 at 04:51 PM.
    Reply With Quote
      #5  
    Old 07-19-2006, 04:39 PM
    renevanh renevanh is offline
    Registered User
     
    Join Date: Dec 2004
    Location: The Netherlands
    Posts: 86
    More advanced way... thank you

    René
    __________________
    Don't take life to serious, you won't survive it anyway...
    Reply With Quote
      #6  
    Old 07-19-2006, 04:50 PM
    James Gatka James Gatka is offline
    Banned
     
    Join Date: Jan 2006
    Location: I'm in GMT -5
    Posts: 561
    Rene:

    You're welcome. Take care. I realized, too late, the information was Name, Address, so forth. I edited my previous post to "widen" the form, and boxes.
    Reply With Quote
    Reply

    Bookmarks


    Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
     
    Thread Tools Search this Thread
    Search this Thread:

    Advanced Search
    Display Modes Rate This Thread
    Rate This Thread:

    Posting Rules
    You may not post new threads
    You may not post replies
    You may not post attachments
    You may not edit your posts

    BB code is On
    Smilies are On
    [IMG] code is Off
    HTML code is Off
    Forum Jump


    All times are GMT -5. The time now is 02:28 PM.



    Acceptable Use Policy


    The Network for Technology Professionals

    Search:

    About Internet.com

    Legal Notices, Licensing, Permissions, Privacy Policy.
    Advertise | Newsletters | E-mail Offers

    Powered by vBulletin® Version 3.7.3
    Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.