When I run a JS function (on a button click) it reloads the page and displays the data the function outputs. However, when I run the JS code when the page loads (no function or button) the script runs fine.
I have tried multiple things to fix the issue such as using a button with type="button" instead of an input. I also tried have the JS function return false. The problem is, I do not have access to the JS and can only implement it, not change it.
JS code without function:
var placeHolder = new Sched({
PID: "Something"
});
placeHolder.write();
When I had a button (with type="button"), removing the placeHolder.write() line would stop the page from reloading, but obviously also prevent the JS from doing its job. I would like to take the HTML produced by placeHolder.write() and add it to some div. I know how to do all this with static data, but I cannot prevent the page from reloading and displaying nothing but what placeHolder.write() prints.
If I need to be more concise, let me know. I had some trouble trying to figure out how to phrase this question...
Edit: Just wanted to add some information to the overall project. I'm making a page for a University. The school provides a page builder which allows for HTML input. The site then takes the HTML you want and adds to it the University's website layout (such as the side bar, header and footer).
The user should be able to enter a certain major's code into an input box, click a button, and the course information should appear below. I've simplified this in my testing to figure out why the page is reloading (also when the button is pressed, the University's website's layout is lost). In my simplification, I've removed the input and form and just have a button which runs a function containing the above code. "Something" is replaced with a major's code (statically). I've tried setting the placeHolder.write() to a div's innerHTML which did not work either.