How to Prevent Page Reload with Javascript onclick Without Using “#”

Just a very short blog jot for today as I’m busy working on a Salesforce.com data analysis tool / system.

Since this is a very low budget project, I’m hand coding everything using Notepad++ and VBScript to create a dynamic web application in old school Acitve Server Pages (ASP) that can consume the analytic data that my system stored on a MS Access database.

Again, low budget. Me and my wits pounding out code.

I ran in to an issue where the web page is calling a JavaScript that passes two variables to an Ajax call to load a Chart.js bar chart in a popup window. 

It was working great but the page that had the onlick event to load the popup chart was reloading as well when clicked instead of just loading the popup window with the chart.

What’s the fix?

Add “return false;” at the like in the example below and the page containing the onclick link should stop reloading when clicked.

Old Code

<a href="#" OnClick="getChart('John Smith', '2017-01');">John Smith</a>

New Code

<a href="" OnClick="getChart('John Smith', '2017-01');return false;">John Smith</a>

I always give credit to the people who helped me find the answer.  I had found the answer in the stackoverflow page below.

https://stackoverflow.com/questions/17680436/how-to-prevent-reload-with-onclick-without

Author: Rick Cable / AKA Cyber Abyss

A 16 year US Navy Veteran with 25+ years experience in various IT Roles in the US Navy, Startups and Healthcare. Founder of FinditClassifieds.com in 1997 to present and co-founder of Sports Card Collector Software startup, LK2 Software 1999-2002. For last 7 years working as a full-stack developer supporting multiple agile teams and products in a large healthcare organization. Part-time Cyber Researcher, Aspiring Hacker, Lock Picker and OSINT enthusiast.