0

I have a form with multiple inputs. I'm trying to specifically send text inputs to a function and have the function return the var as a table. I am able to send the input and return a table, but the table only appears for a brief second when I click a submit button, then the page seems to refresh. I have the submit input set to onclick="function()".

Does anybody have any ideas as to why after I click submit, the page refreshes and I loose the data in the table? I would appreciate some ideas of what the proper way is to go about this problem. Thanks in advance.

1
  • 2
    Questions seeking debugging help ("why isn't this code working?") must include the desired behavior, a specific problem or error and the shortest code necessary to reproduce it in the question itself. Questions without a clear problem statement are not useful to other readers. See: the tour, and read How-to-Ask. What topics can I ask about Commented Aug 11, 2017 at 19:40

2 Answers 2

1

you can use onclick="function(event){event.preventDefault(); /*your code here*/}" to cancel the refresh

Sign up to request clarification or add additional context in comments.

1 Comment

I attempted this and did not have any luck with it. It may have been some incorrect coding on my part though. Doing what was suggested below and changing it from a submit button to a regular button fixed the issue. Thanks!
0

One option might be to use a regular button instead of a submit button:

<button onclick="function()">Function</button>

By the way, I really hope your function isn't actually called function(), but that's a whole other problem...

1 Comment

Thanks! Changing it to a regular button fixed the issue. And no, it is not called function(), just a quick example!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.