Questions tagged [preventdefault]

Javascript event method to cancel the event if it is cancelable, without stopping further propagation of the event.

Filter by
Sorted by
Tagged with
-1 votes
1 answer
29 views

How do I save data in a textarea using preventDefault by using an event listener in jQuery?

pretty new here so apologies for all the questions. I'm making a scheduler that saves notes for different time brackets using jQuery and I'm at a snag where I'm unable to figure out how to have the ...
Ryan Caltabiano's user avatar
0 votes
1 answer
43 views

event.preventDefault(); doesnt work on video click [closed]

I have a video element on my site, I want to require the users to fill out a short form in order for them to be allowed to watch the video. I have this js that opens the form on click $('.gated-...
jmona789's user avatar
  • 2,721
0 votes
0 answers
14 views

Required tooltips on submit form does not appear after the scroll animation

I´ve been trying to make this tooltips appear without using js or something else than bootstrap classes and the required attribute. The problem is that my form is using a prevent default function on ...
Israel Ornelas's user avatar
-1 votes
1 answer
45 views

Ajax call and Fetch did not work on Mobile

I am trying to make a call to an API (Spring boot application which is running on AWS). It is not working on mobile, webpage is refreshed an method onreadystatechange is not called. I also tried using ...
Jorge Robla's user avatar
0 votes
0 answers
15 views

Prevent default in Vue Splide

I am using Vue with Splide slider. Everything worked great with hardcoded images, but now, using axios and GET method for my data, images look weird and they are moved to one side... When I refresh ...
Skar's user avatar
  • 388
0 votes
0 answers
12 views

Django register form validation for javascript

In django i followed form method is model form i not validate in backend only validate frontend using javascript but if click the submit button the data is not store to database how to fix I tried to ...
Abishek's user avatar
0 votes
0 answers
34 views

Why isn't preventDefault preventing my page from reloading?

I am writing a chat application, in the form of a custom element, in vanilla Javascript, but in every time I submit a message (I have not gone about implementing the actual sending the message yet, so ...
Dominus's user avatar
  • 63
0 votes
3 answers
114 views

My react-hook-form's handleSubmit function in Typescript keep reloading the page and not return the results

I copy the exact code from react-hook-form document like this import React from "react"; import { useForm, SubmitHandler } from "react-hook-form"; type FormValues = { firstName: ...
David Tran's user avatar
0 votes
0 answers
10 views

Dropdown inside nav, ul, li tag closing when trying to select despite e.preventDefault()

const DropdownButtons = () => { const SettingsDropdownMenu = () => { const settingsNavRef = useRef(); const [isSettingsActive, setIsSettingsActive] = useState(false); ...
Bryant Irawan's user avatar
0 votes
1 answer
35 views

Jquery form submit, prevent default, unbind -> then submit. What am I doing wrong?

Ok, so I've been scratching my head for the past 3 days. Can't figure out what I am doing wrong. I have the following html structure: <!DOCTYPE html> <html lang="en"> <head&...
cnapsys's user avatar
0 votes
2 answers
30 views

When I submit my form, it refreshes, overriding my preventdefault() method. I can't fix it

I initially had it working, but when I added the dark mode toggle, it began to read the dark mode toggle as a submit event, and would change the colour of the beer bottle and display the enter/Don't ...
davelangham's user avatar
0 votes
1 answer
53 views

Prevent file from being uploaded

I tried to prevent the upload of the file after dragging the file in the input with ev.preventDefault(); . It works but now after dragging the file it doesn't change the file name in the name section. ...
OosoO's user avatar
  • 1
1 vote
0 answers
72 views

Error when using react-scratchcard-v2 on mobile: Unable to preventDefault inside passive event listener invocation

I am using react-scratchcard-v2 to create a scratchcard game. It works fine on desktop, but when using it with touch (either on mobile or in the mobile view of Dev Tools), it still works, but I get ...
Michael Kolesidis's user avatar
0 votes
0 answers
94 views

Next.JS e.preventDefault() not working (Typescript)

I'm using Next.JS with Typescript. The problem is that e.preventDefault() doesn't work, and my input gets cleared on submit. const ModalLatino = () => { const handleSubmitLatino = (e: React....
Lorenzo Alinovi's user avatar
0 votes
0 answers
52 views

Ajax - preventDefault()

<script> var xmlhttp; if(window.XMLHttpRequest) xmlhttp = new XMLHttpRequest(); else xmlhttp = new ActiveXObject("Microsoft.XMLHTTP"); ...
Dawn's user avatar
  • 1
0 votes
0 answers
23 views

Why `title` input doesnt act as `required` when I press enter? [duplicate]

As the title says... I have my input element with required and button with submit type, but also have e.preventDefault() on JS and I dont know if thats the reason why it doesnt work and if so, how to ...
NicoRozo's user avatar
0 votes
3 answers
769 views

How to stop React Overlay from appearing on a specific error

I am trying to stop ResizeObserver loop limit exceeded error from showing up on my development enviornment of my react application. The error is benign How can I get React to stop showing this in my ...
Ashar Rahman's user avatar
0 votes
0 answers
126 views

alpineJS controlled form submits original value instead of x-model sync one

I have an comment section with edit in place functionality. It is a modified version of https://codepen.io/brbcoding-the-selector/pen/yLNvexO with backend submission. On the front end, everything ...
Anonworriedworker's user avatar
-1 votes
1 answer
54 views

e.preventDefault(); is not working in my modules forms, I tried evertything but can't find solution

can someone help me? preventDefault() is not working, I tried to addEventListener('click' or 'submit') if I put click required is not working but if I put submit preventDefault is not working i looked ...
Kukii's user avatar
  • 1
0 votes
0 answers
139 views

How can I prevent a default browser action when using dash-extensions event-listener?

I was trying to add an event listener from the python dash-extensions to the KeyDown input, but it is being overridden by the default browser behavior (scrolling down on the page). Any thoughts on how ...
Ana's user avatar
  • 1
0 votes
1 answer
37 views

How to stop default behaviour of all the links in the entire webpage?

I am creating project which allows users to remove elements from any webpage. The way this work in my project is that it first creates an overlay which allow user to select the elements they want to ...
Ambuj sahu's user avatar
0 votes
1 answer
52 views

React e.preventDefault() error, onClick passing value from map

const onSubmit = (event, val) => { console.log(val); event.preventDefault(); setValues({ ...values, error: "", success: "", key: val }); setDidSubmit(true); }; ...
George Prethesh's user avatar
1 vote
0 answers
38 views

PreventDefault doesnt work in ReactJs Project

So Im going through React Course and I did exactly what I had to do but it seems that I cant execute preventDefault function on form submit and I dont really know why if anyone has any idea please let ...
Zura Gabichvadze's user avatar
1 vote
2 answers
204 views

Form submit preventDefault not working on mobile device

I'm using event.preventDefault on a form submission and it works, but only on desktop devices. When using a mobile device the form is submitted the normal way and the event is not prevented. Here's ...
Justin's user avatar
  • 21
0 votes
0 answers
33 views

Show detail Button in table not working(instead pages gets reload) and Not getting all the data properly of the table from mongodb

As I click on the Show detail button I should get an alert/more info of the user but instead of that the page gets reload. Basically on 'show details' button the 'OnClick' function is not getting ...
GAURI WALKE's user avatar
-1 votes
2 answers
137 views

JS: preventDefault() for the link element <a>

When I click the nested image in the link the download popup appears at the top. How to prevent the default behavior of the link element that is a parent of the image? <div class="gallery&...
Dmytro Kovach's user avatar
1 vote
1 answer
261 views

How do i prevent entering in input any character except letters and one underscore in a row?

I can't create an input in which the first character entered must be a letter, and the following characters can be only letters or only one underscore in a row i have an input and following javascript ...
macr0n's user avatar
  • 21
0 votes
0 answers
20 views

How to prevent link click on slider until it’s in center position?

I need to suspend click events of a link block with a class of "album-link" unless the parent div contains the class, "is-active". then it can be clickable In my test codepen I am ...
Danielle Roberson's user avatar
2 votes
1 answer
107 views

How does stopPropagation cancel preventDefault?

I have a website that does not allow to open up the context menu by clicking the right button on a mouse. It seems like the website does blocking it by using preventDefault on the event oncontextmenu. ...
gtj520's user avatar
  • 196
-1 votes
1 answer
258 views

Jquery: Use preventDefault() to disable only the space bar

I'd like to use the function preventDefault() to disable the spacebar from jump-scrolling down, like it usually does in Chrome, for example. If I try this: $('html').keydown(function(e){ if(e.keyCode ...
Ben Viatte's user avatar
0 votes
0 answers
414 views

Flutter Prevent a ScrollController from scrolling for a given number of pixels

Flutter's DraggableScrollableSheet Widget allows a sheet to be dragged into position and then continue scrolling the content without the user needing to start a new gesture (lift their finger from the ...
Walrus's user avatar
  • 19.9k
0 votes
0 answers
65 views

Having both onclick and OntouchStart is causing next rendered component to get clicked on the same position on screen

I have a react app, and I have to use both onclick and OntouchStart on each button in the app as my clicks were not detectable on iphone for some particular use case. Now I have a drawer, on which I ...
deepak malik's user avatar
0 votes
1 answer
27 views

Is there a way to catch click events earlier than .stopPropagation() gets executed onclick?

The purpose of document.body.onclick = e => console.log(e.target); is to catch all clicks. Unfortunately, the click on the first link won't be displayed in the console. Is there a way to grab links ...
Haradzieniec's user avatar
  • 9,086
-2 votes
2 answers
44 views

I want to stop my website from refreshing

I know i can do it with preventDefault, but i don't know where to set the preventDefault on the code... let navbar = document.querySelector(".navbar"); document.querySelector("#menu-...
JustHarlys's user avatar
0 votes
1 answer
523 views

async event handler and preventing default behavior

I'm having a trouble wrapping my head around this problem: suppose I have a form where I want to handle onSubmit using async callback through event listener and I want to prevent the default behavior. ...
RomanM's user avatar
  • 93
0 votes
1 answer
313 views

I use json-server to post data with fetch the data added but the page reloaded even I use e.preventDefault, I need the page not reloaded

I use json-server to post data with fetch after I click submit button the data added but the page reloaded even I use e.preventDefault, I need the page not reloaded, I don't understand the problem ...
Bassem Zaki's user avatar
0 votes
2 answers
47 views

Created "Buy X, Get Y Free" Script, How To Prevent Script From Running If Customer Removes Y?

In our store, I wrote a script that if a customer buys 1 out of 13 total valid items, another item (y) would be automatically added to their cart and be made free. The issue I am running into is that ...
Ryan Meza's user avatar
0 votes
0 answers
127 views

Js unable to prevent default action for cmd+w inside chromium(brave) browser

Im using react-hotkeys-hook library to assign a shortcut to keyboard combinations. cmd+r/cmd+t are being prevented from their default behavior but when it comes to cmd+w it doesnt. here is the library ...
Sarkis 's user avatar
0 votes
0 answers
33 views

jQuery form Ajax submit issue

I have a div (#ajax-progress) containing multiple forms. I'm trying to get the div contents reloading when any of the forms are submitted. If I do this: $("#ajax-progress form").click(...
Sam's user avatar
  • 907
1 vote
1 answer
34 views

Why doesn't e.preventDefault() stop my page from Refreshing?

I just can't figure out, why my site is loading when pushing the submit-btn. Even though I tried to prevent this with e.preventDefault() in my function. Maybe someone can open my eyes.. I'm sitting ...
maierphilipp's user avatar
1 vote
0 answers
51 views

When the window is loading the event stops. After scrolling down the event starts

(function () { var previousScroll = 0; $(window).scroll(function(){ var currentScroll = $(this).scrollTop(); if (currentScroll > previousScroll){ event....
Giman Lee 's user avatar
0 votes
1 answer
900 views

Preventing page refresh after form submission (e.preventDefault();) doesn't work

I want to stop page refresh after the user submits the form. The problem is that it doesn't seem to work. PHP: <?php function displayimage() { $con = mysqli_connect("localhost&...
Astw41's user avatar
  • 394
6 votes
0 answers
1k views

How do you use preventDefault() in React-Native

I am using TextInput of react-native-paper on IOS. I want to use preventDefault for button Enter, Tab, , buttons but I can't find the preventDefault method for react-native. Is there a preventDefault ...
Furkan's user avatar
  • 61
0 votes
0 answers
17 views

reference to e.preventDefault [duplicate]

Why reference to this object's method works const obj = { hi: () => alert('hi') } obj.hi() // 'hi' const myMethod = obj.hi myMethod() // 'hi' But reference to the event's object method ...
Anton Arbus's user avatar
0 votes
0 answers
132 views

Append prevent duplicate jquery

I have this code var values = ["15", "30"]; var select = $('<select class="form-control">').prop('id', 'fcorte').prop('name', 'fcorte'); $(values).each(function(e) {...
user3673405's user avatar
0 votes
0 answers
44 views

Why is e.preventDefault() a function and not a property

Why was e.preventDefault() defined as a function and not as a property, for example e.preventDeafult = true;? Wouldn't there even be advantages of it being a property, since you could set e....
LuisAFK's user avatar
  • 846
0 votes
1 answer
668 views

Disable 'submit' button unless box is checked

Following on from a previous question I asked Submit button not working with JS validation I have been really struggling with getting the checkbox being checked to be part of the form validation. my ...
Yenmangu's user avatar
0 votes
1 answer
165 views

link event.preventDefault doesn't work in a popup overlay window

I'm trying to prevent users to open directly unsafe links (http://). here below is the code I'm using: const container = document.querySelector('#container-id'); let links = container.queryselectorAll(...
Anton's user avatar
  • 11
0 votes
1 answer
274 views

Prevent default on select focused

I am trying to prevent default on press F1 so it doesn't open a new tab to support.google.com, instead I want to use it as a hotkey for my app, this is working everywhere, except when I focus a select ...
imvenx's user avatar
  • 214
0 votes
1 answer
491 views

react app resets state and rerenders without e.preventDefault on click

I have a react app that seems to be resetting all of its state and re-renders the entire app when button is clicked: the form + button: <form> ... <button onClick={(e: React....
tomyhomie's user avatar
  • 344

1
2 3 4 5
20