I've got a really simple function I want to create, a confirm delete function that is applied to all links with a class of delete. A confirm message appears when the link is clicked, returning false if cancel is clicked.
This is my code and for whatever reason that I just don't get (coz I'm a bit confused by all this stuff), clicking cancel when the confirm message appears seems to return true regardless. Code:
I have an iframe that includes a button: <input type="button" value="close this window" onclick="window.close();" >
I would like to detect the iframe close event from the parent window, I was using this code but I did something wrong because the temp function is fired every time the parent page loads:
function temp(){ alert('the iframe was closed'); } function setup(){ var myIFrame = document.getElementById("iframe1"); if (myIFrame.addEventListener) { myIFrame.addEventListener('onclose', temp(), false); }else if (myIFrame.attachEvent) { myIFrame.attachEvent ('onclose',temp); }else{ myIFrame.onclose=temp(); } } window.onload=setup;
How do I add an event listener to a few text boxes that prevents the user from typing anything but digits. I use the numbers entered in the text boxes in calculations afterwards so I don't want the user to enter "one" instead of "1" etc... Also, the range of possible numbers is too big for a drop down menu.
I'm writing a custom script to collect attributes from links and concatenate them to pass as a string to another function. I'm using a readily-available 'addListener' function so the click event doesn't overwrite others on the page. All this seems to be working in all browsers except IE6, and I suspect it may have something to do with event bubbling. Can anyone see my errors and any other ways I could improve the script? Code:
I'm trying to use the addEventListener function to set an event listener but I don't understand why it won't work. Before i was using another method to handle events, but I needed more control over which event handlers get run and when.
Code:
<html> <head> <script type="text/javascript"> function runMe(){
[Code]....
I'm using Google Chrome, but it won't work in Firefox either. Obviously it won't work in IE, since IE doesn't support that method. The script gives no errors at all. The runMe() function does get executed, I tested this with alerts.
I want each instance of an object to be able to listen for input events. When the event occurs, a method of the object should be called, such that "this" is in scope and refers to the object instance.
Is this possible? Example:
function MyConstructor(element) { //element is some HTML element this.addListeners(element);
Inline scripting makes this easy but I'm getting Typeof MissMatch error when I use Unobtrusive script and I think it's because of the diffrence between DOM and DHTML.
INLINE:
HTML Code:
Unobtrusive attach event listner/external js.
Code:
This writen in the js of the index.html containing the IFRAME 'display' runs once imediatley on load then imediatley after throws 'typeof mismatch' error.
I have a form with many, many, many 'input type="text"' elements in it. I'd like to be able to dynamically add an 'onKeyDown' event listener. Here's what I've got, so far (I know it's wrong.)
Code: function addEventToElement(formName,tagName,typeName,eventName,eventAction) { thisForm = (typeof formName == 'string') ? document.getElementById(formName) : '' ; thisTag = (typeof tagName == 'string') ? tagName : '' ; thisType = (typeof typeName == 'string') ? typeName : '' ; thisEvent = (typeof eventName == 'string') ? eventName : '' ; thisAction = (typeof eventAction == 'string') ? eventAction : '' ; if(thisForm != "") { // If elements are in a form, make sure ONLY those elements are affected elem = new Array(); elem = thisForm.getElementsByTagName(thisTag); // array of all items of [tag] alert(elem.length); if(thisType != "") { for(j=0;j<elem.length;j++) { if(elem[j].type != thisType) { elem.splice(j,1); } // If a type is specified, remove tags that do not have a type attribute } } } else { // Otherwise, any/all elements in a document/body will be affected elem = new Array(); elem = document.getElementsByTagName(thisTag); // array of all items of [tag] if(thisType != "") { for(j=0;j<elem.length;j++) { if(elem[j].type != thisType) { elem.splice(j,1); } // If a type is specified, remove tags that do not have a type attribute } } } if((thisEvent != "") && (thisAction != "")) { for(i=0;i<elem.length;i++) { // All elements are picked - let's apply some attributes document.getElementById(elem[i].id).addEventListener(thisEvent,thisAction,false) } } }
HTML Code: addEventToElement('form_name','input','text','keydown','return numbersOnly(event,this);');
I tried to append a table row to a table by clicking on a button. And inside the table, I put a link so i can click that and remove the row. I was using jquery.flydom plugin, by the way. [code]...
I'm working with nested functions and trying to pass a 'this' value to an anonymous being used in an assignment for an event listener.So, this should plop a button inside our DIV and when clicked I'd like it to run the alert-ding; unfortunately it seems to want to run the function as defined under the buttons object which doesn't work out too well.
Event Listener. From what I understand it will check all events until a defined event happens, such as rollover of a certain image, and then it activates a function? What I want to do is use this so that when I rollover a element such as below: <img src="img url" alt="this is a tooltip" tooltip="true" /> I want it to pass the obj to a function which then runs, and then once the mouse of not over that element it will activate another function passing the previous object to this function.
Although an element such as the example below would not activate these functions: <img src="img url" alt="this is a tooltip"/> As the tooltip tag does not exist or has the value of false. Also, wouldn't this use a lot of resources as it checks every event which the mouse passes over?
I am trying to add a window event listener on some links in a loop instead of doing them one by one. I've tried
function setListeners (){ for (var i = 0; i < document.links.length; i++) { src=document.links[i].href; document.links[i].onmousemove=changeIframeSrc(src, 'solid',1, event); document.links[i].onmouseout=changeIframeSrc(null,'none',0,event);
I am testing some code that finds and element and attempts to add an event handler attribute to it as 'onclick' (test case in Firefox 3.5.9)
/* The actual code is: window.onload = function() { //<irrelevant code> var test = document.getElementById('tstEl');
[Code]...
I am trying to do this because Element.addEventListener or Element.attachEvent won't allow for arguments to be passed to the event handler code/function. What is going on here? The only line referenced, line35, in the document text containing javascript code is irrelevant to the problem.
I need to pass the 'id' variable from the event listener to the callback function, 'moveObject'. The moveObject function needs to know the id of which element it should act upon. How can I pass this variable?
I'm not new to JS, or the web and it's various other technologies, but I ran into a problem. I'm trying to add an event handler for a click on all HTML span tags. Trouble is, getElementByTags() doesn't work and neither does getElementByTagNames(). Strangely, adding an id to the span tags and getting their id's do trigger the handler.
Code: document.getElementsByTagName('span').addEventListener('click',doSomething,false); function doSomething() { alert(this);
How would i add an avent listener to change the source of an image? I have added the image to a canvas element through javascript using the code below.
var start = new Image(); start.src = "start.jpg"; ctx.drawImage(start, 50, 50);
I have an XHTML STRICT page which has some event listeners attached for onload and resize. I'm doing a bit of Javascript DHTML on these events. When a user changes the browser font size, the javascipt function needs to run. Although the TOPMENU DIV gets resized when the font changes size, its not a page resize so the function doesn't get run. I fixed this in IE6 by using a second function which is run onload and sets an event on the div object in the page after its been defined.
Problem is this doesn't work in Firefox.
Mozilla DOM reference says there is no resize event on a DIV so is there a work around to make it work in FIREFOX? i.e. can I force a resize event to happen on a div in firefox or is there some other event I can trap when a user changes the browser font size?
here's my js code: topmenu is what I'm trying to trap the resize event from.
I am writing a Javascript UI component. I have already written a "disable()" method for it, but I would like to go one step further in order to make my component as compatible with existing HTML controls as possible.
With standard HTML controls we can do this: myTextField.disabled = true; and as soon as this property is set, I assume there is a property listener of some kind that is invoked to change the appearance and value etc of the control.
I want to write my own 'property listener' to do this with my control. Can I do it in Javascript or is this too "low level", requiring code at the browser implementation level?
I am using the following code to add a keyup event listener to the body tag. It works fine in Webkit and Chrome but FF and IE just do nothing. The event never fires. However, no javascript errors occur in any browser.
here is the code:
Code:
var Body = new Object(); Body.trackKeys = function (target){ if( document.getElementsByTagName("BODY")[0].addEventListener ) {
I am wondering about what seems to be a particular quirk in Javascript that does not allow form event listeners (e.g. "onsubmit=...") to work properly. In the code below, I would like to set up a function (doOnSubmit) that is called when the form is submitted.
But there is a "return false;" in the "onclick" of the button. If this "return false" is removed, the code works as I would hope it would. With it there, doOnSubmit is never called. Code:
I'm working on an event driven app, which currently adds a listener to each of the relevant elements directly. I am planing on changing this to use a delegated event method but this raised the following question...Which is more expensive navigating the DOM, or adding event listeners?[code]I need to handle the click event of buttons 'b1', 'b2' & 'b3', a set of these buttons can be found in each 'a1' container but not always in the same nested position. To handle the events I need to know the class of the button clicked and the id of its 'a1' container. Would it be more efficient to:
A ) Add just one listener to the 'main' div, having to find the 'a1' containers id by inspecting each parentNode of srcElement until an 'a1_*' match is found.
B ) Add a listener to each 'a1' container, the id of the container can be easily passed as an argument.