FAQ Database Discussion Community


Adding .onclick listeners in javascript loops [duplicate]

javascript,ajax,javascript-events
This question already has an answer here: JavaScript closure inside loops – simple practical example 25 answers I have a page getting JSON data via AJAX. I've managed to parse the data and create table rows from it. I'm now trying to add .onclick listeners to those rows using...

jquery fire page load event from loaded page

jquery,javascript-events,jquery-load
I'm loading a php page in a div with $("#div").load("page.php?id-blah") The page gets loaded correctly and jquery is functioning properly. In the page.php I am using the $(document).ready(function() { ...perform things.. }) call but its not fired. What event do I have to use to make `perform things run? ...

Identify select option change (change, onchange, click) event through JavaScript or jQuery

javascript,jquery,javascript-events,jquery-events
Is there any way to know when the select option is changed through event other than onchange in the select? For example, through jQuery. $('select').val('2'); $('#someButton').click(function() { $('select').val('2');}); Meaning that if I change the select value by click on the button, I may be prompted a message. But when I...

jQuery selector precedence when using pattern matching

javascript,jquery,javascript-events,jquery-selectors,event-handling
I am creating a form that implements a bunch of similar elements. They are custom select boxes, created out of <ul>s. Some of these elements are slightly different in the way I want the mousedown event to be handled though. The way I have it set up currently is that,...

Node.js EventEmitter events no longer triggered on node 12.1+

node.js,events,javascript-events,eventemitter
I have stripped the problem back to the following code: var EventEmitter = require("events").EventEmitter, util = require('util'); function Foo() { EventEmitter.call(this); } util.inherits(Foo, EventEmitter); Foo.prototype.on('hello', function() { console.log("World"); }); Foo.prototype.start = function() { console.log('Hello'); this.emit('hello'); } var foo = new Foo(); foo.start(); Using Node v0.10.36 this code outputs: Hello World...

EventTarget.addEventListener()'s useCapture argument use?

javascript,javascript-events
I am studying the vanilla JavaScript and I have some trouble understanding what is the use of this useCapture argument in the EventTarget.addEventListener() function. https://developer.mozilla.org/en-US/docs/Web/API/EventTarget/addEventListener useCapture Optional If true, useCapture indicates that the user wishes to initiate capture. After initiating capture, all events of the specified type will be dispatched...

Javascript onpaste event of everytext box value should be split and paste in corresponding textbox

javascript,javascript-events
Strictly no jquery please I have text 1234ABC984IK4H2J and I have four text box onpaste i need text to split and copied in remaining text box Purely in javascript no jquery as my application doesn't support jquery and IE>8 functions so no function supports like querySelectorAll and addEventlistener HTML <td><input...

What's the pattern for calling requestAnimationFrame multiple times per frame?

javascript,javascript-events,css-animations,requestanimationframe
I have a touch handler that may fire multiple times within a given 16ms time period. On each firing, I set a translate on the element based on the touch position, eg: at 2ms, translate 20px at 5ms, translate 40px at 10ms, translate 50px I understand that calls to rAF...

Why is my Java script code not running? (Form Validation)

javascript,html,javascript-events
This is my HTML: <html> <head> <title>Article</title> <link rel="stylesheet" href="pop.css" type="text/css" /> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> </head> <body> <script type="text/javascript" src="validator.js"></script> <div id="comment_form"> <form method="POST"> Name: <input type="text" name="name" id="name1" onblur="checkname()"> <br/> Email: <input type="text" name="email" id="email1"...

Is there an event for onclick end?

javascript,jquery,html5,javascript-events,onclick
I have a code in which should only be executed after an onclick event. On mobile devices its fine because I use touchstart and touchend. Is there an event similar to touchend for use on a computer? My code currently looks similar to.. document.getElementById('trigger-box').addEventListener(function(e) { // the event will be...

How is the “e” parameter assigned to the event?

javascript,javascript-events
I can see a few threads around the e parameter but there is one thing I can't fully understand, though I'm sure it's an obvious answer. When the e parameter is passed into a function that's called from addEventListener() the e looks to be assigned to the event object. What...

Make function work synchroniously (wait local events to get fired)

javascript,javascript-events,synchronous
I'm having problems with JavaScript logic. When we have a function that needs data from event-handler to generate result, is it possible to get that data back to function? For example, if we call Image() object or FileReader() inside and wait for its load event to get fired in order...

Why is my node event callback showing up in the event as undefined?

javascript,node.js,url,javascript-events
I am trying to pass back a url string as "data" into my eventhandler. My request to the server is "https://172.20.10.6/index.html". The console.log below prints out "/index.html" as I expect. switch(req.method) { case 'GET': console.log("logged from plugin-https.js: url: " + req.url); ee.emit("dataIn", req.url); break; Below is the eventHandler code. The...

AngularJS - Click event (in directive) triggers when anywhere in the parent is clicked

javascript,angularjs,javascript-events,angularjs-ng-transclude
I'm going to do my best to explain my issue - bear with me. This whole thing is a directive for file selection: The directive has an ng-transclude component that contains a few directives, contained in their own divs. Parent directive: <div class="extra-cells"> <div ng-transclude class="extra-cells-row"></div> </div> ng-transclude content: <div...

Prevent checkbox from checking itself

javascript,javascript-events,stoppropagation
I have some <li> which is styled as a button. <li class="button"> <input type="checkbox" class="checkbox" /> <span>Text</span> </li> As you can see, there is a checkbox inside the li element. I use angular to set checked property of this checkbox as we click li area. It works fine, but I...

Google maps event listener dragend

javascript,google-maps,google-maps-api-3,javascript-events,google-maps-markers
I am adding a event listener to my marker, the function for the marker is function setupMarkerWaypoint(){ console.log('setting waypoint marker'); waypointMarker = new google.maps.Marker({ position: default_latlng, map: mapBooking, icon:"http://maps.google.com/mapfiles/ms/micons/blue.png" }); waypointMarker.setVisible(true); function geocodePosition(pos) { geocoder.geocode({ 'latLng': pos }, function(responses) { if (responses && responses.length > 0) { updateMarkerAddress(responses[0].formatted_address); } else...

How to make multiple balls drop on click?

javascript,canvas,javascript-events,html5-canvas
I have a ball that drops from cursor location, and redrops when the cursor is moved to another location. I am trying get a new ball to drop every time I click the mouse. I tried: canvas.addEventListener('click', function(event) { ball.draw(); }); But it doesn't seem to do anything. Is there...

Javascript override form onsubmit event not working

javascript,forms,javascript-events
I am overriding a form submit event like this: form.onsubmit = function(event) { event.preventDefault(); But when I call submit on the form like this in a separate function: form.submit(); The onsubmit function is not called and the and the form is posted as usual. Any thoughts? Edit: I am also...

How to make a react component that can be rendered with no data and later rendered with data?

javascript,javascript-events,reactjs
I have a situation that I'm sure is common and I just haven't learned the react way for accomplishing it. Let's say I have this: var appView = new React.createClass({ render: function() { return ( <div> <SomeSubview/> </div> ) } }); React.render( React.createElement(appView), $('#app').get(0) ); My question is how should...

IndexedDB: Can you manually initiate a version change transaction?

javascript,html,javascript-events,google-chrome-extension,indexeddb
I am writing a chrome extension that utilizes IndexedDB to store some information client side in an IDBObjectStore within an IDBDatabase. The nature of the data is such that I need my users to be able to modify the object store at their whim. (add new objects modify existing ones...

Move a button created dynamically JavaScript

javascript,javascript-events
I am a very beginner! I've dynamically created a random number of buttons. After creation, I want them to automatically start moving. From some reason or another, my code creates the buttons, but doesn't make them move. Thanks a lot! javascript.js function myFunction() { for (i = 1; i<=Math.random() *...

Why isn't my Google Tag Manager event listener being installed?

javascript-events,google-analytics,google-tag-manager
I have a very simple Google Tag Manager trigger that looks like this: I also have a corresponding tag that uses this trigger. I have published my container, and the tag shows up when previewing/debugging the container: I also see my link's id in the response from GTM. However, I...

HTML 5 Drag & Drop Functionality - Remove Dropped Item

javascript,html5,javascript-events
I'm almost there. I'm creating drag and drop functionality and the last part i'm having issues with is finding a clean way to remove the item that has been dropped. The yellow div is draggable. The red div is droppable. When the yellow div is dragged on top of the...

How to handle “click” event even if element is moved from beneath the cursor between mousedown and mouseup?

javascript,jquery,html,javascript-events
I have an <input> and a <button>. The input has an onblur event handler that (sometimes) results in the <button> being moved; if, with focus on the <input>, the user goes to click on the <button> (and it is thereby moved from beneath the pointer before the click completes) they...

Change the functionality of a button

javascript,jquery,html,javascript-events
Currently I have a display where I have a button START, on click of this button the timer starts and it gets replaced by 2 buttons. these 2 buttons are submit and walkaway. on the submit of each of these buttons a script is run. on the click of submit...

Basic Calculator - event binding using pure javascript

javascript,javascript-events
I am completely new to the Javascript .When I am looking to get the value to the button its get failed.I already given the setEvent.Like getEle(); And also bind the click function, Now i want to get the input values and perform mathematical calculations. <!DOCTYPE html> <html> <head> <title>Simple Calculator</title>...

How to run a Javascript function everytime f5 is used to refresh the page

javascript,jquery,javascript-events,onload-event
The following code works for the first time that the page is loaded but when the page is refreshed using F5, it does not work on firefox. In chrome it works fine. $(document).ready(function() { $("iframe").each(function() { // Using closures to capture each one var iframe = $(this); iframe.on("load", function() {...

Why am I getting an uncaught type error with the following code?

javascript,javascript-events
The purpose of this code is to have 3 divs that change color when clicked and when the two colors in divs on the left make up the one on the right the user receives a positive message either on the console or the DOM. I thought I had this...

Fire event when images in generated content are loaded

javascript,html,javascript-events,dom-events
I've got a problem with some Javascript-generated content : I use the onload() event of my html page to load HTML code from a server and inject it in the page. Since it already is html I use the innerHtml property of the nodes I want to fill with content....

Javascript TypeError for declared function

javascript,javascript-events
HTML <input type="checkbox" class="test" id="chk" /><label for="chk">Click</label> <p id="demo"></p> JavaScript (function (){ var chk = document.querySelector('.test'); function ClickTest(elem){ this.elem = elem; }; ClickTest.prototype.addListener = function() { this.elem.addEventListener('change', this.showValue); }; ClickTest.prototype.showValue = function(){ console.log('Clicked'); var d = document.getElementById('demo'); d.innerHTML = "This works"; this.test(); }; ClickTest.prototype.test = function(){...

Why is 'event' available globally in Chrome but not FF?

javascript,jquery,javascript-events,event-handling,global
While working on an answer for another question, a strange bug came up related to the event object being available in an anonymous function without being passed in. In Chrome the below works fine, but FF throws an error. $(document).ready(function() { $("#uspsSideboxTrackingClose").click(function() { event.preventDefault(); console.log(event); }); }); Chrome: FireFox: ReferenceError:...

Track Links Using Events - Race Conditions

javascript,angularjs,javascript-events,google-analytics,adobe-analytics
I am building AngularJS applications which have common header with links to each of the application: <a href="https://app1.company.com">App1</a> <a href="https://app2.company.com">App2</a> Each application is running on its own subdomain and when user clicks a link on the header - page redirects to that application. I have to track user actions with...

Asp.NET: How to trigger OnCommandClick first than OnClientClick

c#,asp.net,visual-studio-2012,javascript-events
I am crating a session inside the OnCommandClick to save informations about a file that will be downloaded. If I click to download it, the OnClientClick works fine and I can download the file. But when I have a grid with more than one file, I think that the function...

On condition fire all events, else fire none

javascript,jquery,javascript-events
I am working on top of existing javascript (that I can not alter) and need to check something on submit. If my condition is true, no other submit handlers should be applied. If my condition is false, all other submit handlers shall be applied. What I have tried so far:...

what does onclick='mycheck(“+i+”)' do?

javascript,javascript-events
Im fairly new to javascript and would appreciate your explaination on this code. i was provided with the below code as an example and needed to make some changes too it but im unsure what onclick='mycheck("+i+")' is meant to do. i know its calling the function mycheck() but not sure...

JQuery event propagation (return false)

javascript,jquery,javascript-events,event-handling
Why clicking on the male radio button does not work? <div id="m_wrapper"> <input id="m" type="radio" name="sex" value="male" />Male<br> </div> <input id="f" type="radio" name="sex" value="female" />Female <input id="o" type="radio" name="sex" value="other" />Other $("#m_wrapper").click(function(e){ $("#m").prop('checked', true); return false; }); I know that here -> return false is equivalent to call e.preventDefault() AND...

Highcharts & jQuery: add a mark by clicking with Shift key pressed, then process on release

jquery,javascript-events,highcharts
I am working with Meteor (means jQuery ok) and Highcharts. For data analysis purposes, users need to be able to set markers between two initial markers by clicking on the chart. I want them to be able do that as long as shift key is hold down. Here the algo:...

Can a conditional-And operator(&&) contain more than 2 operands?

javascript,html,events,javascript-events
I asked a question in regards to this code earlier and it works to a degree after I changed it to reflect the answer but there is a bug that only really you to match red with red or blue with blue or green with green. I know that the...

sublime-scroll plugin is not scrolling as expected (iframe event catching issue)

javascript,jquery,iframe,javascript-events
I want to read mouse position from an iframe. I am doing it with this implementation: $($("#sublime-scroll-iframe").contents()[0], window).find('body').bind("mousedown", function(e) { console.log("x:" + (e.pageX) + ", y:" + e.pageY); } ); My working example: http://jsfiddle.net/s37e1ro0/1/ but I can't make it to work with demux's sublime-scroll js script. Output is window coordinates...

Why is sortable event target null

javascript,javascript-events,sortable
Using RubaXa Sortable, I'm doing a pretty standard (given it's an example on the library's site) drag of an item from one a group to another. I need to store the original and target group ids as variables. All works well except the target is always NULL. The example on...

Javascript function called with button onclick, fails with onload

javascript,html,javascript-events
I am trying to use an external javascript function in the body tag : <!DOCTYPE html> <script type="text/javascript" src="js/Long.min.js"></script> <script type="text/javascript" src="js/ByteBufferAB.min.js"></script> <script type="text/javascript" src="js/ProtoBuf.min.js"></script> <script type="text/javascript" src="js/fs.js"></script> <script type="text/javascript" src="js/bundle.js"></script> <script type="text/javascript"...

How do I avoid hover event to fire in iPhone and iPad?

javascript,ios,iphone,javascript-events,jquery-hover
I had added an effect on hoverEnter and hoverLeave on my Divs assuming that these events wont fire on iOS devices. But on iOS devices the hoverEnter and click event fire and the hoverEnter effect is maintained. I dont want these hover events to fire on mobile devices. What should...

How to get a deleted element in a contenteditable div?

javascript,html,html5,javascript-events,html-select
I set the root div to contenteditable, and it contains many img and video elements. So when a user edits it and presses backspace to delete one element, How can I get which one the user deleted and get the deleted element's attributes values?

Jquery Click event dosen't fire on paranet div that has same size as descendent img?

jquery,javascript-events,event-handling
The HTML code is as below (the img fits to the div parent) : <div id='draggable_task' style='display: inline-block; position: relative; overflow: hidden'> <img src='../Content/BPMN Icons/Big Icons/BigTask.png' /> <p style='position: absolute; top: 20%; left:20%;'>Task name</p> </div> The JavaScript code is as below (DrawArea is the top container): $("#DrawArea").on("click", function (e) {...

Why does the form submit event fire when I have stopped propagation at the submit button level?

javascript,jquery,forms,events,javascript-events
HTML <form> <input type='text'> <button type='submit'>Submit</button> </form> JavaScript $('form').on('submit', function(e) { alert('submit'); e.preventDefault(); }); $('button').on('click', function(e) { e.stopPropagation(); alert('clicked'); }); Fiddle After watching the great video here, I understand that when I click the submit button, the event bubbles up to the form, and the form's submit event is then...

Using javascript or jquery to auto populate the current time

javascript,jquery,html5,javascript-events
I am trying to use javascript and/or jquery to auto populate the time in an type time field; not the date. It auto populates fine. However, i am trying to have it auto populate the current time rather than a specified time. (e.g."17:40:11") How do I get the current time...

Publisher in Pub/Sub should be Synchronous or Asynchronous?

javascript,design-patterns,javascript-events,anti-patterns
My view on mechanism: Pattern wise publisher should just publish an event and should not care about listeners / subscribers for that topic / event. In case of JavaScript, lot of frameworks for Pub / Sub publishes event in Sync manner for example : framework just maintains map of event...

Conditionally include script for browsers

javascript,jquery,javascript-events,reference,conditional-statements
I have such kind of script code setTimeout(function () { $('.grayscale .inactive img').each(function () { $(this).wrap('<div style="display:inline-block;width:' + this.width + 'px;height:' + this.height + 'px;">').clone().addClass('gotcolors').css({ 'position': 'absolute', 'opacity': 0 }).insertBefore(this); this.src = grayscale(this.src); }).animate({opacity: 1}, 500); $(".grayscale li").hover(function () { $(this).find('.gotcolors').stop().animate({opacity: 1}, 200); }, function () {...

Avoid Adding Event Multiple Times

javascript,javascript-events,mootools
I am dynamically adding events using addEvent("keydown", function() {}); to an element. My problem is that there are times when this code get's run on the same element twice or more. The behavior becomes clunky as the function registered for that event runs a couple of times. Is there a...

How to get a button's ID when clicked in Windows 8 apps?

javascript,html,javascript-events,click,windows-8.1
I'm trying to get the ID of the button I clicked but I can't do it. I tried everything but it doesn't work. How can I do this? ...

In iframe how to “unwrap” span tags

javascript,jquery,jquery-ui,javascript-events
how to unwrap span tags within Iframe. <span id="trans001" class="newtext">Directional</span> i tried to remove using this $('iframe').contents().find(".newtext").unwrap(); If remove() means it works but content also removed. i want to retain text. Thanks in advance....

Accessing 'this' table cells value

javascript,dom,javascript-events
I have a form, after form has been filled and add button pressed - all the values from the form get to PouchDB and then into the table in the browser. I need to make an "edit" option. The idea is: <td ondblclick='updateVaucher()' style='cursor: pointer'>"+data[i].doc.vaucherID+ "</td> Now the question is:...

polymer on-click event inside content wont trigger?

javascript,javascript-events,polymer
I'm very new to Polymer so don't shoot me.. How do I use the 'core-icon-button' on-click event to trigger a method that is contained inside of its parent polymer-element aka 'my-component'. Below is an example of what I'm trying to achieve. You can see that there is an element called...

Bind multiple events in javascript

javascript,html,javascript-events
I tried the following to change a span to red on mouseover and black on mouseout: <span onmouseover="this.style.color='red' onmouseout=this.style.color='black'">Mouse over me!</span> but it does not work! How can I bind more than one event to a single element using javascript?...

Why are two click events registered in this html/css/jquery

javascript,jquery,html,css,javascript-events
I am trying to style a checkbox list. I've added my styles and they appear correctly when rendered. I want to add a class when the label for the checkbox is clicked. This is my markup and here is the same in a jsfiddle. You can see from my fiddle...

Setting the onclick event to a custom function results in syntax error

javascript,javascript-events,onclick
Given the following example code I want to set the onclick event to a function which I declare in the same method (no function in global scope): <HTML> <HEAD> <Title>Title</Title> </HEAD> <body> <img id="img" class="std" src="http://www.free-animated-pictures.com/bug_crawls_on_screen.gif"/> <script type='text/javascript'> var i = document.getElementById("img"); var func = function(){ var i = document.getElementById("img");...

Using values from a Datalist to populate a input field

javascript,javascript-events
I am trying to populate an input field based off of a datalist selection. So if a person chooses the name jimmy.johns, the input field should populate with 5555555555. Here's my code. <html> <head> <title>Countdown</title> <input name="customer" list="customer" /> <datalist id="customer"> </datalist> <br> <br> <input id = "phone" name ="phone"...

jQuery Text Editor (jqte), using change event

javascript,jquery,javascript-events,jqte
I am trying to write some code for change() event using jQuery Text Editor (jqte), I have two functions which give jqte functionality to textarea's One for editors loaded with Javascript, when clicking some elements in a page function onLoadEditor(){ jQuery(".comment-editor").jqte({ // some jqte params, such as fsize: false,indent: false......

onended audio event firing without playing the audio

javascript,html5,audio,javascript-events
I have multiple audio files that i need to be played. and only when all audio has been played completely the next section is supposed to show. the code that i've written fires automatically without playing any audio. how should i do it? here's my code <!DOCTYPE html> <html> <body>...

Can't Add Up Radio Button Values with jQuery

javascript,jquery,html5,jquery-mobile,javascript-events
I'm trying to add up all the values of the radio buttons selected on Submit button press. It sometimes changes the 0 to a 200, but it isn't adding correctly. I'm not quite sure what is going on with this one, since the total amount sometimes changes, but isn't accurate....

How is Facebook able to autoplay videos on mobile browsers

facebook,jquery-mobile,javascript-events,facebook-javascript-sdk,html5-video
I realize that many questions have been asked about autoplay videos on mobile devices but before my question is marked as a duplicate, I must say that I looked through a lot of those questions and answers and I have not found a satisfactory answer. Mostly, all of the answers...

Extjs5 - right click context menu with Ext.form.field.HtmlEditor

javascript,extjs,javascript-events,event-handling
Problem description I have prepared this index.html, which creates a simple Ext.form.field.HtmlEditor. I want to have a right-click-context-menu, which is capable of doing something with words that were marked by the user: <!DOCTYPE html> <html> <head> <script type="text/javascript" src="/ext-5.1.1/build/ext-all-debug.js"></script> <link id="theme1" rel="stylesheet" type="text/css" href="/ext-5.1.1/build/packages/ext-theme-neptune/build/resources/ext-theme-neptune-all.css"> <script...

How to (sort of) add code to fullcalendar's renderEvents handler?

javascript,ajax,javascript-events,fullcalendar
I'm using fullcalendar 1.6.3 along with Drupal 7 (thus the need, for now, to be back on 1.6.3). I have some code that I'd like to run every time the view of my calendar changes (via ajax requests) -- forward or backward in time, or between month/week/day view. Based on...

What WheelEvent.deltaZ refers to?

javascript,javascript-events,mousewheel
While I was working on JavaScript events, I found a troubling element on the wheel event: the deltaZ member. I understood what was deltaX as horizontal scroll (available with some devices like a touchpad) and deltaY as vertical scroll (that is what any standard wheel do) but for deltaZ, the...

Uncaught SyntaxError: Unexpected token with mouseover event in D3 Treemap

javascript,d3.js,javascript-events,mouseover,treemap
I am working on putting together a zoomable treemap using D3. I'm starting with basic code at https://gist.github.com/vibster/3257874. I'm including the git for the whole code, but will include the relevant section below. To the cell variable, I am adding a mouse over function from this previous answer: Zoomable treemap...

Send an event using $emit from directive to controller

javascript,angularjs,javascript-events
I'm trying to send an event when an item gets selected, from directive to controller using $emit. I've two update functions for organizations and another for people. My directive should specify which event should emit. Here is my update functions // For organization $scope.updateOrgs = function(selectedVal) { } // For...

jQuery event for HTML5 datalist when item is selected or typed input match with item in the list

javascript,jquery,html5,javascript-events
I have datalist like below - <input id="name" list="allNames" /> <datalist id="allNames"> <option value="Adnan1"/> <option value="Faizan2"/> </datalist> What I want is, when an item is typed in completely(for example say in input box when user completely type "Adnan1") or selected from list, then I want an event. I tried couple...

How to prevent my jQuery textarea Focus event from firing repeatedly for ulimted times in a row

javascript,jquery,javascript-events
I have something like the basic JavaScript jQuery code below that is only called once in my project code however it alerts 100+ times when my textarea attached to the event is focused by clicking my mouse cursor into it! projectTaskModal.cache.$cmtTextarea.on('focus', function() { alert('ON FOCUS EVENT'); }); My goal is...

How to reset the complete document after opening it?

javascript,pdf,javascript-events,reset,acrobat
i want to reset the complete form after opening it. I have tried this: page.open = this.resetForm(); But it doesn't work. Im using Acrobat Pro DC....

jQuery event.preventDefault() don't work unless debugging

javascript,jquery,events,javascript-events,event-handling
I am trying to use this approach in order to convert GET parameters to POST. I also want the anchor to be properly handled even if the middle mouse button is clicked. This is how I did the the event handlers binding: $(document).ready(function () { $(".post").each(function(){ $(this).mousedown(function(evt){ switch(evt.which){ case 1:...

How do I know, via key event code, if the character just entered in a