-1

I have a page with some javascript that add or remove some controls. Everything is working perfectly except when the page is viewed from Chrome (PC and ipad version). The problem is that my page reload when a button is clicked. The button event call a function

myButton.onclick = function () { myFunction(param1, param2); };

and the function is

function myFunction(param1, param2)
{ 
    var formToRemove = document.getElementById(param1);
    document.getElementById("div_" + param2).removeChild(formToRemove); 
    return false;
}

The 'return false;' is there because one of the post I've read suggested to add that line to prevent the page reload but this haven't helped me so far.

Any help will be greatly appreciated.

Etheryte
  • 24,589
  • 11
  • 71
  • 116
Elound
  • 49
  • 4
  • 14

1 Answers1

1

I think this post will help you:

All you need is to assign type="button" on your button control.

Your markup would look like the one below:

<button type="button" id="myButton">My Button Text</button>

And I think if you use button with type="button" set on the markup, you probably don't need to return false at the end of the function.

Community
  • 1
  • 1
dhruvpatel
  • 1,249
  • 2
  • 15
  • 23
  • Thanks! I simply added "myButton.type = 'button';" and the reload issue is gone. – Elound Sep 15 '14 at 15:40
  • I hate to admit how long I spent trying to debug why my page was reloading. Who'd have thought that a – Mike Cargal Oct 19 '15 at 15:14