Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    New to the CF scene
    Join Date
    Sep 2013
    Posts
    2
    Thanks
    1
    Thanked 0 Times in 0 Posts

    HTML page reloads after dynamic change

    Hello, I am editing an Html page that needs to be updated based on the button pressed by the user. I.E. if the user clicks a "Show" button, the page needs to create dynamically a table showing some values on a JS object .
    The problem is, the dynamical table creation goes ok, but after about a second , the table disappears from the page , as if the page itself has reloaded (in effect it HAS reloaded) losing reference to the dynamically added table object.
    What can I do to avoid this unexpected reload of the page, so to keep the dynamically created object on the page itself ? And more, why does the page reload after the call to "document.body.appendChild(..)" I use to add the table ?

  • #2
    Senior Coder
    Join Date
    Dec 2010
    Posts
    2,355
    Thanks
    11
    Thanked 558 Times in 551 Posts
    It shouldn't ... so there has to be a different part of your code that forces the reload. But without any of your code we won't be able to tell

    Common pitfalls
    - A <button> element is a submit button by default. Specify type="button" to avoid the submit. A submit will lead to a reload if no action is specified on the parent form
    - A change of window.location.href (even a subtle one) will also cause a reload. Only changing the hash part will avoid this

    etc etc

  • Users who have thanked devnull69 for this post:

    towmdj (09-24-2013)

  • #3
    New to the CF scene
    Join Date
    Sep 2013
    Posts
    2
    Thanks
    1
    Thanked 0 Times in 0 Posts
    I guess you pinpointed the problem. In effect I am using a <button> tag , not a <input type="button" >..... this is an option I never tried .
    Thank you for the support.

  • #4
    Senior Coder
    Join Date
    Dec 2010
    Posts
    2,355
    Thanks
    11
    Thanked 558 Times in 551 Posts
    It doesn't matter whether you use <input type="button"> or <button type="button"> as long as you specify the type :-)

  • #5
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    10,964
    Thanks
    0
    Thanked 236 Times in 233 Posts
    You can still use submit button, you just have to return false in the onclick handler to prevent the default submit action.


  •  

    Tags for this Thread

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •