javascript - Simple mulch caculator won't fire on click and no error. jQuery and straigt js -
i'm attempting convert straight javacript function fire jquery .click
i'm not getting output errors yet wont perform calculation on jsfiddle.
var form = document.product_form_top; function process(v) { var value = parseint(document.getelementbyid('item_qty').value); value += v; document.getelementbyid('item_qty').value = value.tofixed(0); } function calculate() { form.cubicyards.value = (form.length.value / 3) * (form.width.value / 3) * (form.depth.value / 35); document.getelementbyid('yards').innerhtml = finaloutput var number = parsefloat(form.item_qty.value); var finaloutput = number.tofixed(0); form.item_qty.value = form.cubicyards.value * 14.7; //calculate yards var number = parsefloat(form.cubicyards.value); var finaloutput = number.tofixed(0); document.getelementbyid('item_qty').innerhtml = finaloutput form.weightpounds.value = (form.length.value / 3) * (form.width.value / 3) * (form.depth.value * 21); form.weightpounds.value * 700; var number = parsefloat(form.weightpounds.value); var finaloutput = number.tofixed(0) document.getelementbyid('pounds').innerhtml = finaloutput }
here's jsfiddle http://jsfiddle.net/4l4st/8/
here's working version using onclick="calculate(); on button run function. rather use jquery's .click function fire it.
http://spartonenterprises.com/store/playground-mulch
also, i'm using tofixed(0) remove decimal points , appears work when inspecting firebug, visible html shows decimals. strange?
i edit fiddle here: http://jsfiddle.net/4l4st/5/, example; have basic mistakes example can try again.
i edit html way:
<div class="control-group clearfix"> <div class="rubber-nugget-calc"> <label class="control-label" for="item_qty"> <h2>calculate bags</h2> </label> <div class="clear"></div>length: <input type="text" name="length" size="3" class="sidebarinput" />(feet) width: <input type="text" name="width" size="3" class="sidebarinput" />(feet) <br/>depth: <select class="depthselect" name="depth"> <option value="">please select one</option> <option value="1">1 inch</option> <option value="2">2 inches</option> <option value="3">3 inches</option> <option value="4">4 inches</option> <option value="5">5 inches</option> <option value="6">6 inches</option> <option value="7">7 inches</option> <option value="8">8 inches</option> <option value="9">9 inches</option> </select> <!--calculate button --> <button class="calculate" type="button" style="float:right;" class="button">calculate bags needed</button> <!--results--> <p>you need approximately:</p> <div class="calc-results"> <div id="yards" style="display:none;"> <span> (results) </span> </div> <span class="mulchspan" style="display:none;"> total cubic yards of mulch </span> <input type="text" id = "cubicyards" name="cubicyards" size="2" class="sidebarresult" value="" /> <div class="clear"></div> <div id="pounds" style="display:none;"> <span style=""> (results) </span> </div> <span class="mulchspan" style="display:none;"> pounds of mulch (*for bulk delivery) </span> <input type="text" name="weightpounds" size="6" class="sidebarresult" /> </div> <label class="control-label" for="item_qty">approximate bags needed</label> <br/> <br/> <small>*note - round 1 bag ensure coverage / may use calculator or manually enter amount.</small> <div class="controls"> <div class="button-div"> <input type="text" id="item_qty" name="item_qty" class="input-mini" value="" /> </div> </div> </div> </div>
and function this:
$(".calculate").click(function () { alert('sdfasgg'); document.getelementbyid('cubicyards').value = 12; document.getelementbyid('yards').style.display=""; document.getelementbyid('yards').innerhtml = 25; document.getelementbyid('item_qty').value = 26; document.getelementbyid('pounds').style.display=""; document.getelementbyid('pounds').innerhtml = 27; });
-------------------------------update---------------------------------------
this final fiddle http://jsfiddle.net/4l4st/13/
with fixex decimals
its doesnt calculate can make calcs in best way; working code example.
Comments
Post a Comment