Super Sale Limited Time 50% OFF for All-Access Plans
Save 50% Now

Buttons submit probleme


hello i finish my code but the " always realod when i click on it without my code works please help me how can i remove the fking realod


Text formatting options
Submit
Click any option to insert into your comment. Select text first to wrap it.
  • **text** to make things bold
  • *text* to emphasize
  • ### Heading to make headings
  • [link text](url) for links
  • ![alt text](image-url) to paste in an image
  • - item to make a list
  • 1. item to make an ordered list
  • > quote to quote somebody
  • `code` for single line of code
  • ```js ... ``` for JS code block
  • ```html ... ``` for HTML code block
  • ```scss ... ``` for SCSS code block
  • ```php ... ``` for PHP code block
  • --- for a horizontal rule
  • happy  :)
  • shocked  :|
  • sad  :(

Replies (7)


Hi,

If you use the buttons' default behavior it submits the form on click. To avoid this you can use the below code in the bottom of your page, after all core-js scripts includes:


// On document ready()
KTUtil.onDOMContentLoaded(function () {
const myBtn = document.querySelector("#myBtn");
myBtn.addEventListener("click", function (e) {
e.preventDefault();
});
});


Regards.



why i can't share the code ?



so how i can add it here

<div class="form-group text-center">
<input type="hidden" name="token" value="<?=$_SESSION["token"] ?>"/>
<input type="submit" class="btn btn-primary" value="Mettre &agrave; jour"/>
</div>



that's the demo2 metrocnic file if you don't have i give you



Not the HTML code btw, just the event handler that you are trying to fix

If it is a form causing the problem, it's most likely that the default action is your pain.

When you submit a form the page reloads, so the server can process the information, if you don't want that behavior you need to add

preventDefault
on the event handler.



on jQuery you can do something like

$("#formId").on("submit", function(e){
e.preventDefault;
---- your code
})



Can you share a little more information about your code?

Besides. Try adding e.preventDefault soon after the click


Text formatting options
Submit
Click any option to insert into your comment. Select text first to wrap it.
  • **text** to make things bold
  • *text* to emphasize
  • ### Heading to make headings
  • [link text](url) for links
  • ![alt text](image-url) to paste in an image
  • - item to make a list
  • 1. item to make an ordered list
  • > quote to quote somebody
  • `code` for single line of code
  • ```js ... ``` for JS code block
  • ```html ... ``` for HTML code block
  • ```scss ... ``` for SCSS code block
  • ```php ... ``` for PHP code block
  • --- for a horizontal rule
  • happy  :)
  • shocked  :|
  • sad  :(
Text formatting options
Submit
Click any option to insert into your comment. Select text first to wrap it.
  • **text** to make things bold
  • *text* to emphasize
  • ### Heading to make headings
  • [link text](url) for links
  • ![alt text](image-url) to paste in an image
  • - item to make a list
  • 1. item to make an ordered list
  • > quote to quote somebody
  • `code` for single line of code
  • ```js ... ``` for JS code block
  • ```html ... ``` for HTML code block
  • ```scss ... ``` for SCSS code block
  • ```php ... ``` for PHP code block
  • --- for a horizontal rule
  • happy  :)
  • shocked  :|
  • sad  :(