preventdefault

Prevent submit button with onclick event from submitting

末鹿安然 提交于 2019-11-29 06:11:01
I want to prevent a submit button with onclick event from submitting: $j('form#userForm .button').click(function(e) { if ($j("#zip_field").val() > 1000){ $j('form#userForm .button').attr('onclick','').unbind('click'); alert('Sorry we leveren alleen inomstreken hijen!'); e.preventDefault(); return false; } }); This is the submit button: <button class="button vm-button-correct" type="submit" onclick="javascript:return myValidator(userForm, 'savecartuser');">Opslaan</button> It will show the "alert" function and also removes the onclick event, but the form is submitted anyway. Manually remove the

jquery select dropdown ignores keydown event when it's opened?

邮差的信 提交于 2019-11-28 07:47:12
问题 I'm trying to prevent backspace button to go one page back in every browser. For now I'm using this code: $(document).on("keydown", function (e) { if (e.which === 8 && !$(e.target).is("input, textarea")) { e.preventDefault(); } }); It works fine for everything except when a select field dropdown list is opened , this event is ignored and a backspace takes me one page back anyway. How can I solve this problem? Thank you for your answers. 回答1: Just for the info, this is Google Chrome specific

React onClick and preventDefault() link refresh/redirect?

岁酱吖の 提交于 2019-11-28 07:07:32
I'm rendering a link with react: render: -> `<a className="upvotes" onClick={this.upvote}>upvote</a>` Then, above I have the upvote function: upvote: -> // do stuff (ajax) Before link I had span in that place but I need to switch to link and here's the trouble - every time I click on .upvotes the page gets refreshed, what I've tried so far: event.preventDefault() - not working. upvote: (e) -> e.preventDefault() // do stuff (ajax) event.stopPropagation() - not working. upvote: (e) -> e.stopPropagation() // do stuff (ajax) return false - not working. upvote: (e) -> // do stuff (ajax) return

event.preventDefault vs event.stopPropagation [duplicate]

时光总嘲笑我的痴心妄想 提交于 2019-11-28 06:29:23
This question already has an answer here: What's the difference between event.stopPropagation and event.preventDefault? 7 answers Can someone explain what's the difference between event.preventDefault() and event.stopPropagation() ? I have a table and within that table I have an img tag. When I click the img tag, I want to see a popup. But I also want to stop the selection of multiple rows, so I use: $("table.items tbody tr").click(function(event) { event.stopPropagation(); }); When I use the js code, the popup does not appear; If I delete the js code, the popup works. $(".info").live("click"

Is this a core misunderstanding of the default click event on checkbox inputs, or flawed code?

懵懂的女人 提交于 2019-11-28 04:31:48
问题 When binding to a click event for a checkbox input, the checkbox is already toggled by the time my event handler runs and, more oddly, the toggle is reversed after my event handler runs if I specify event.preventDefault(); <input id="foo" type="checkbox"/> function clicked(evt) { alert(document.getElementById('foo').checked); evt.preventDefault(); } document.getElementById('foo').addEventListener('click',clicked); [tested in chrome and firefox] JSFiddle for that code The alert will respond

Prevent submit button with onclick event from submitting

落花浮王杯 提交于 2019-11-27 23:27:13
问题 I want to prevent a submit button with onclick event from submitting: $j('form#userForm .button').click(function(e) { if ($j("#zip_field").val() > 1000){ $j('form#userForm .button').attr('onclick','').unbind('click'); alert('Sorry we leveren alleen inomstreken hijen!'); e.preventDefault(); return false; } }); This is the submit button: <button class="button vm-button-correct" type="submit" onclick="javascript:return myValidator(userForm, 'savecartuser');">Opslaan</button> It will show the

Can't prevent `touchmove` from scrolling window on iOS

六月ゝ 毕业季﹏ 提交于 2019-11-27 20:06:16
We are trying to scroll an element on our iOS web app while preventing the window itself from scrolling. We are capturing the touchmove event on the window, scrolling the element programmatically and (trying to) prevent the window itself from scroll by calling preventDefault on the event. Unfortunately this doesn't work in Mobile Safari. The window continues to scroll underneath our element. The issue sounds exactly like the Webkit bug described in https://bugs.webkit.org/show_bug.cgi?id=163207 , but that issue was supposedly fixed in iOS 10.3 whereas I am running 11.3. Catching

Ctrl+S preventDefault in Chrome

删除回忆录丶 提交于 2019-11-27 18:44:25
I Want to catch Ctrl + S in Chrome, and prevent the default browser behavior to save the page. How? (Just posting the question & answer as I was after this for a pretty long time and didn't find a solution) zupa As far as I can see, the secret sauce is, that Ctrl + S does NOT fire the keypress event, only the keydown event. Using jQuery.hotkeys : $(document).bind('keydown', 'ctrl+s', function(e) { e.preventDefault(); alert('Ctrl+S'); return false; }); Only with jQuery: $(document).bind('keydown', function(e) { if(e.ctrlKey && (e.which == 83)) { e.preventDefault(); alert('Ctrl+S'); return false

PreventDefault alternative for IE8

南笙酒味 提交于 2019-11-27 16:02:44
Situation : Trying to modify VideoJS.com in order to work with IE8 and Youtube Chromeless API. Problem : Progressbar dragging doesn't work (error on event.preventDefault(); 'not supported' according to debug) Demo : http://alpha.dealertouch.mobi/video/demo.html What I tried : Skip 'preventDefault' when it's IE, but if I do that I'll lose the functionality of the progressbar (drag/click forward and backward) Question : What is the best way to solve this problem for IE8? I use something like: (event.preventDefault) ? event.preventDefault() : event.returnValue = false; the event.returnValue

When to use PreventDefault( ) vs Return false? [duplicate]

青春壹個敷衍的年華 提交于 2019-11-27 06:13:56
This question already has an answer here: What's the difference between event.stopPropagation and event.preventDefault? 7 answers Firstly, in JavaScript's event model, you will come across a concept called as event bubbling (which makes an event to propagate from child element to a parent element). In order to avoid such kind of bubbling effect, many developers use an event method called stopPropagation( ) . Alternatively, developers have started to use return false statement to stop such propagation. Now, there is another terminology called preventDefault( ) . As the name indicates, this