0

I am writing a code to add two number and display the result on another page. But I am not getting the desired output.

addbtn=button id add=result page id calc= starting page id....here is my code:

// Bind to 'page init' event for our data page
$(document).delegate('#calc', 'pageinit', function() {

  // Do some processing when the button with id 'addbtn' is clicked ( or tapped )
  $('#addbtn').click(function() {

   // Read the values
   var num1 = $("#num1").val(), num2 = $("#num2").val();

   var add =  parseInt(num1) + parseInt(num2) ;
   $add = $('#add');

   // Clear the value if value isn't proper
   if (add == '0.000' || add == 'Infinity' || add == 'Na N') {
     add = '';
   }        
   // Get to the DOM node that has the actual text
   while ($add.children().length) {
     $add = $add.children().first();
   }

  // Set it to the calculated value
  $("#add").text(add);
  });
});
Gajotres
  • 57,309
  • 16
  • 102
  • 130
Khippal
  • 11
  • 2
  • 1
    what is your question? Please make a fiddle: jsfiddle.net – Alp Mar 04 '13 at 08:32
  • Welcome to Stack Overflow. The question title should be a summary to call the attention of those who may know the answer. Additionally, you're expected to explain what your code attempts to do and how it fails to accomplish it. You can edit your question and improve it. – Álvaro González Mar 04 '13 at 08:36

1 Answers1

0

Instead using .click() use .on() with click and tap:

$('#addbtn').on('click tap', function() {

and one more change use .on() instead .delegate():

$(document).on('#calc', 'pageinit', function() { 

Note:

.on() requires jQuery version 1.7+

Jai
  • 74,255
  • 12
  • 74
  • 103