Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2

Thread: checkboxes & ff

  1. #1
    New Coder
    Join Date
    Feb 2007
    Location
    FL
    Posts
    35
    Thanks
    4
    Thanked 0 Times in 0 Posts

    checkboxes & ff

    have a simple calculator i made with checkboxes and some Js.

    the problem is that it does not work in FF.

    any idea how this can work for
    IE
    Safari
    AND FF


    Code:
    function getPrice(amount, boxName){
    		total = eval() ;
    	
    		checked = document.getElementById(boxName).checked
    			if (checked){
    				total =  parseFloat(form1.Total2.value) + parseFloat(amount);
    
    			}else{
    				total =  parseFloat(form1.Total2.value) - parseFloat(amount);
    
    			}
    			total.toFixed(2);
    		form1.Total2.value = total
    		document.getElementById("total").innerHTML = "Total $"+total;
    	}

  • #2
    Regular Coder Amphiluke's Avatar
    Join Date
    Jul 2009
    Posts
    312
    Thanks
    3
    Thanked 89 Times in 89 Posts
    FF expects from you use the getElementById method instead of direct referring by the name of a form.
    Code:
    <script type="text/javascript">
    	function getPrice(amount, boxName){
    		var checked = document.getElementById(boxName).checked;
    		var form1 = document.getElementById("form_1")
    		if (checked){
    			total =  parseFloat(form1.Total2.value) + parseFloat(amount);
    		} else {
    			total =  parseFloat(form1.Total2.value) - parseFloat(amount);
    		}
    		form1.Total2.value = total.toFixed(2);
    		document.getElementById("total").innerHTML = "Total $"+total.toFixed(2);
    	}
    </script>
    
    <form action="#" name="form_1" id="form_1">
    	<input type="checkbox" name="box" id="box" value="box" /> I am a checkbox<br />
    	Total: <input type="text" name="Total2" /><br />
    	Amount: <input type="text" name="Amount" />
    	<div id="total">&nbsp;</div>
    	<input type="button" value="get price" onclick="getPrice(this.form.Amount.value, 'box');" />
    </form>
    I am still learning English


  •  

    Posting Permissions

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