return - Javascript code disappears after button click -


i'm trying make sub-total calculation tool, can't continue because don't know problem is. when form submitted, or button clicked, disappears.

here's fiddle :: http://jsfiddle.net/xfmbk/

i'm clueless...

    function calcsub(){          var input = document.getelementbyid('fld'),             subtotal = document.getelementbyid('sub-total'),             tax = document.getelementbyid('tax'),             total = document.getelementbyid('total');          var subtotalcalc = input.value / 1.06;          var flag = true;           if(input.value == "" || input.value == null){             alert("please enter in total!");             return false;         } else {             subtotal.innerhtml = "subtotal:" + " " + "$" + subtotalcalc;             tax.innerhtml = "tax:" + " " + "$" + input.value - subtotalcalc;             total.innerhtml = input.value;             return flag;         }      } 

that happens because submit button form submit on action , page being refreshed. there ways fix behavior, such as:

make submit button button: <input type="button"> doesn't seem need form there

or add return false onclick handler:

<button type="submit" onclick="calcsub(); return false;">calculate</button><br> 

Comments

Popular posts from this blog

image - ClassNotFoundException when add a prebuilt apk into system.img in android -

I need to import mysql 5.1 to 5.5? -

Java, Hibernate, MySQL - store UTC date-time -