I'm quite new to javascript and need help to firstly get value from checkbox (which should tell the code that user going to get -25%) and then calculate the price with discount. At the moment my code let's user to input number (how much is wanted) and then javascript calculates the number and outputs it to <p id=test>...</p>
. I have tried different kind of codes for discount and outputting it but because of my knowledge (at least I think so) they won't work. I can't see if javascript is getting some information from checkbox or not.
PS: The most important for me is to get javascript understanding what is the value of checkbox. Calculating I guess isn't hard :)
My html code looks like this:
<body>
<p style="color:green">Check the checkbox to get discount</p>
<h2 style="display:inline;">
<input type="checkbox" name="checkbox1" id="checkbox1" class="css-checkbox" value="25" />Item:</h2> LiPo Battery 3S2P 5200mAh
<p style=float:right>Quantity:
<input type="text" id="Text" value="">
<button onclick="funktsioon()">Price</button></p><br>
Item price: <input type="hidden" id="price" value="29.30"><b>29.30</b> euro
</p>
<br>
<b><p id="test">Full price: ... euro</p></b>
<b><P id="test3">Price with discount: ... euro</p></b>
And javascript:
<script> function funktsioon() { var price = document.getElementById("price").value; var mult = document.getElementById("Text").value; var fprice = (mult*price).toFixed(2).fontcolor("green"); document.getElementById("test").innerHTML = "Full price: " + fprice + " euro"; var disc = document.getElementById(checkbox1).value; ...need some code here... i guess. document.getElementById("test3").innerHTML = "Price with discount: " + some_kind_of_var_i_guess? + " euro"; } </script>
Aucun commentaire:
Enregistrer un commentaire