Kevin Aartsen Kevin Aartsen - 1 month ago 5
HTML Question

Jquery showing once after submit

I made this form and added some jquery to it. The jquery part is supposed to make a div show if i click on submit.
It does this but only once the it refreshes the page and the div goes back to hidden. I have everything in the same file the jquery and the php and the html.
How do i make the jquery stay.

<form class ="form" method="post">
<h3>Select your trademark</h3>
<select class="form-control" name="trademark">
<option></option>
<option>©</option>
<option>™</option>
<option>®</option>
</select>

<h3>Your company name</h3>
<input class="form-control" type="text" name="companyName" action="">

<br/>
<br/>

<button class="form-control" type="submit" name="submit">
Generate
</button>
</form>

<script>
$("button.form-control").click(function(){
$(".codes").show();
});
</script>


EDIT:

Tried prevent default with Jquery it works it doesnt reload but it doesnt post the filled in data from form in my page.

Answer

Add onsbumit="return false" to your <form>. By returning false from the onsubmit handler you prevent the form from being submitted (no further requests are sent to the server, and the page is not reloaded).