adding a result of a calculation to a span with javascript (jQuery) after a button is clicked -


hi wrote jq i'm not sure correct :) me figure out how

1.when user clicks button (show results)

2.the 2 figures added , result displayed in span # result

3.check on user input, warning, if there no number entered text boxes

only pure jquery please :) thank in advance help. http://jsfiddle.net/4ke8k5vp/

<body>  <div id="wrapper">      <p>         <input type="text" id="num1" placeholder="enter number" value="" />          +          <input type="text" id="num2" placeholder="enter number more" value="" />          =          <span class="alert" id="result"></span>     </p>      <input type="button" value="show results"  />    </div> 

 $(document).ready(function () {               var num1 = $('#num1');             var num2 = $('#num2');             var total = num1 + num2;              $(":button").click(function () {                  $("span").html();               });            }); 

in javascript need cast $('#num1') , $('#num2') int or float parseint() or parsefloat() before adding them. also, in html, input type should number, not text.

the whole javascript funtion should more this

$(":button").click(function () {     var num1 = $('#num1').val();     var num2 = $('#num2').val();     if (num1 == "" or num2 == "") alert("please fill both inputs");     else {         var total = parseint(num1) + parseint(num2);         $("span").text(total);     } } 

Comments

Popular posts from this blog

css - SVG using textPath a symbol not rendering in Firefox -

Java 8 + Maven Javadoc plugin: Error fetching URL -

datatable - Matlab struct computations -