Event Listeners Won't Use Correct Objects / What To Fix It?
Sep 27, 2011
I feel like I must be missing something simple but I can't put my finger on it...
I'm moderately new to JS (programmed in other languages though) and am working on a Google Maps project.
This piece of code should show an alert of the region's name when a map polygon is clicked. Instead, no matter what polygon is clicked, it only does the name for the LAST iterated placemark. code...
What am I missing? What would be a better way of handling this?
View 5 Replies
ADVERTISEMENT
Aug 11, 2004
Here's the situation: I have a javascript object for controlling a custom DHTML scrollbar. So that I can use more than one on a page, the event listeners need to be passed a reference to the particular instance of the object that each needs to connect to, but as I discovered the hard way, inside an event listener, 'this' returns a reference to the DOM object throwing the event, rather than to the JS object. Short of coming up with a linked list of different objects and having the event handler search through it for the right object when an event is generated, then writing a reference to that object to some global variable, is there any convenient way to tie this together? I hope I've made myself clear enough...
View 5 Replies
View Related
Feb 24, 2009
So I know all about the caviats of the 'this' keyword when calling object functions from event listeners:
Code:
var foo = {bar: true, zoo: function() { return this.bar; }};
foo.zoo();
> true
a = foo.zoo;
a();
>
And I know that I can get around this by using an anonymous function so that 'this' is preserved in it's original context:
[Code]...
But then someone pointed out this article on memory leaks when using anonymous functions to call object methods because the anonymous function gets access to ALL variables in the enclosing environment and my not be properly disposed of by the garbage collector [URL] So that lead me to think about using a "3rd-person" approach to referencing object properties from within object methods.
[Code]...
View 2 Replies
View Related
Jun 29, 2011
I am creating JS objects that have some properties that contain DOM nodes, and some of these DOM nodes have event listeners attached to them. When I delete such objects, do I first need to remove the event listeners attached to some of the DOM nodes? And do I need to use removeChild on the DOM nodes that are properties of the object? Or does JavaScript take care of all that?
View 1 Replies
View Related
Dec 16, 2010
The DOM Level 3 specification has a section (1.2.2.2) that talks briefly about "groups" of event listeners. What does this mean? Is this similar to attaching event listeners with a namespace, as in jQuery: "event.my_namespace"?
View 2 Replies
View Related
Dec 21, 2004
I'm used to just using getElementById to look stuff up in my own scripts but I'm doing an assignment and it would not look good to put id's everywhere to modify a html page when there are already name attributes in the elements.
In this page I can't refer to the Family Name input box using document.form1.familyName for some reason. Is it because it's inside a table after the form is opened? What syntax should I be using? Code:
View 3 Replies
View Related
Sep 9, 2009
Does anyone know where I can find a complete list of DOM/DHTML event types documented?
I'm trying to learn more about advanced event handling in JavaScript and I'd like to find lists of event types that I can attach/add event listeners to. I've been searching around and I've found a few resources, but nothing that seems complete.code...
View 4 Replies
View Related
Sep 28, 2009
I'm having problems removing the event listeners, they dont seem to be removed
(I am currently only checking for non-ie browsers) code...
View 2 Replies
View Related
Oct 29, 2007
I have PHP file called file1.php with an empty <div></div> in the middle. I've added a 'load' event listener so that on page load, it calls an AJAX function that calls file2.php. file2.php creates a table and loads it into the <div></div> in file1.php.
file2.php has <a> tags in it's <th> columns and I wish to trap when a user clicks on the column heading. The old way was to use the onclick() method but I'd rather use event listeners.
Here's my problem. I am getting "obj has no properties" when trying to add those listeners. I *think* it is because the code in file2.php isn't part of the original DOM tree for file1.php. So how can I use event listeners instead of onlclick()? I know I can add top the DOM by creating elements and appending them but that adds to the HTML code and my code is already in place via the AJAX call. What to do...? DO I just use the old passe onclick() method?
View 1 Replies
View Related
Dec 3, 2009
I'm trying to add event listeners to multiple elements of the same class. The DOM is something like this [code]...
View 5 Replies
View Related
May 24, 2009
When catcheck1 is unchecked, I want catcheck9 to uncheck. Why does this not work?
<html><head>
<script type="text/javascript">
// Checkbox event listeners.
function checkboxs() {
document.mapform.catcheck9.checked = false;
}
</script></head><body>
<form action="" name="mapform" id="mapform">
<input type="checkbox" id="catcheck1" name="catcheck9" onclick="checkboxs()" checked />
<input type="checkbox" id="catcheck9" name="catcheck9" checked />
</form></body></html>
View 7 Replies
View Related
May 7, 2009
Im trying to write a code to draw random numbers, like a lottery generator. It will require the user to input amount of numbers per line & choose the amount of numbers. From the numbers the user inputs it will generate random numbers to that guideline.
I have wrote the random number function, that works fine. Im having problems invoking it with ONCLICK event handlers. I cant seem to get the correct arguments. And all i get in return is "undefined"
This is the form for the onclick button
<INPUT TYPE = "button" NAME = "drawBalls" VALUE ="Draw the Balls!"
ONCLICK = "lotteryForm.drawnNumbersTextBox.value = ">
Now Im not putting up to much code, as its part of an Assignment, I dont want to cheat, i just want to be pointed in the right direction. :(
View 2 Replies
View Related
Dec 29, 2009
I wrote a simple code in javascript and it is working fine with IE and Firefox but the out put in php array count is correct in IE but not correct in Firefox
<script language="javascript">
var arrdimensions = {
"codimesion":{"s":{'0':'dimesion1','1':'dimesion2','2':'dimesion3','3':'dimesion4','4':'dimesion5','5':'dimesion6','6':'dimesion7'},"c":1,"m":"50", "sc":1, "f":"nopcs[]"}
};
function adddimensions(what) {
[Code]...
View 1 Replies
View Related
Jun 28, 2011
I'm trying to build an SVG-based galaxy map for a space game, it pulls the details from MySQL using PHP and seems to work fine with the following code:
<a xlink:href="index.php?locate=galaxy&sub=planet&x=$x&y=$y" target="_top">
<circle cx="$x" cy="$y" r="$starRadius" fill="rgb($fill)">
<title>$name</title>
[code]....
View 3 Replies
View Related
Oct 24, 2009
On touchstart and touchmove event, the event object has touches and targetTouches properties (see http://bit.ly/Q6uOD), however the jQuery.Event doesn't seem to copy these properties. I tried adding them to $.event.props like this:
$.each(['touches', 'targetTouches'], function(){
if (!($.inArray($.event.props, this))) {
$.event.props.push(this);
}
});
But it doesn't seem to work. The event an event listener received via jQuery hasn't the targetTouches property even if it's accessible via event.originalEvent.targetTouches or window.event.targetTouches.
View 1 Replies
View Related
Jun 2, 2010
I am trying to add onclick event handler to many objects but I can't understand why it doesn't work. To assign event handler I use traditional approach as described in [URL]Heres the code (extract.js):
Code JavaScript:
//the class
function extract(){
[code]....
I know that both select tags don't have options, but I generate them with JS because they hold sequential numbers and this part has no impact on the problem at hand.Both functions help select next or previous index in a given select tag for greater comfort
View 5 Replies
View Related
Sep 14, 2009
I have 2 or more objects that onclick(), will call the same function. Right now I have the following:
....
$("#obj1").change( function() {
setupPage();
});
$("#obj2").change( function() {
[Code].....
I was wondering if there is a way to simplify or clean up the code, since they are all doing the same thing and responding to the same event. This is just for refactoring reasons because my code is getting too long/messy.
View 2 Replies
View Related
Jun 2, 2010
I have this code
<script type="text/javascript">
jQuery(document).ready(function(){
$("select").click(function(){
alert($(this).attr('id'));
});
});
</script>
<FORM><select name="category" id="#link1">
<option value=1>1</option>
<option value=2>2</option>
</select></FORM>
<FORM><select name="category" id="#link2">
<option value=1>1</option>
<option value=2>2</option>
</select></FORM>
<FORM><select name="category" id="#link3">
<option value=1>1</option>
<option value=2>2</option>
</select></FORM>
When I click on any of the select fields, I always get 3 subsequent alerts, each with the id of the clicked select field. What I would like is to have only 1 alert with the clicked select id, whenever I click it.
View 2 Replies
View Related
Dec 26, 2011
[URL]..Default.aspx I have both a carousel with images andalso animagemap(notnot published yet)with coords that when clicked i want to write to a cookie file which image or image map coordinate was clicked, so when they are hyperlinked to the next page the correct div opens based on first reading the cookie written to on the previous page. Anybody have a basic script for reading and writing to a cookie using jquery in this fashion?
View 2 Replies
View Related
Apr 17, 2011
Is there a way in Javascript or Jquery to return an array of all objects underneath a certain point, ie. the mouse position. Basically, I have a series of images which link to various web pages but I have a large semi transparent image positioned over the top of the other images. I want to find the href of the background image that the mouse pointer clicks over.
View 1 Replies
View Related
Aug 2, 2011
I know this isn't a jQuery question per se, but maybe there is an easier way to do this is jQuery than in javascript?
<script>
I was wondering if there is a better way to accomplish the above? Rather than directly changing the innerHTML of the element is it possible to add a onclick listener (or another javascript listener) to the element in a more direct way without having to go through the html.
View 1 Replies
View Related
Apr 23, 2010
I have a quandary of sorts here dealing with a list of checkboxes and the hiding/showing of a few divs associated with the checkbox selection. Here's basically what I need to do: Hide the lower div if no checkbox is selected. If any one of the first 6 checkboxes are selected, and NOT any of the remaining 6, then show the div. If at any time during selection one of the remaining 6 checkboxes are selected, then hide the associated div. Note this code doesn't really do much. I'm still trying to architect a solution that's best.
var aThroughf = false;
var gThroughl = false;
$('[name="'+q2030.name+'"]')).live('click', function() {
[code]....
View 16 Replies
View Related
Sep 5, 2009
Is there a better way to extend object with internal objects?
$.fn.bestShow = function(s) {
var d = {
width: 0,
height: 0,
order: "numeric",
orderBy: "",
[Code]...
View 3 Replies
View Related
Apr 30, 2010
I'm trying to come up with a better architecture for dealing with multiple listeners in a multi-page questionnaire. Here's the general structure I'm looking to implement:
1. Set up CSS for animation
2. Look for preconditions
3. Initialize listener
4. Execute animation
Some issues to consider:
1. Some questions have dependencies that show or hide depending on what is selected in a parent question.
2. Needs to be IE 6 compatible.
3. It should be simple enough so that all you need to do is add a new question to a JSON object, which is what I have set up right now.
Some code (the looping structure that reads each question):
var newQ = eval(q);
$.each(newQ, function () {
// 1 - Setting CSS for each listener
$(this.css).css({'width': '1500px', 'float': 'left', 'clear':'both'});
[Code].....
The problem here is that when I do a console.dir on $.each(this.value.length), it counts each character, as opposed to counting the number of elements in the array. Should I be doing an eval on q? Why or why not? If I could get this up and running, it would make my life 100x easier, as there are hundreds of questions, and I'd want to make this all data driven.
View 10 Replies
View Related
Sep 15, 2010
I have taken over from a developer who has used javascript to add additional text input boxes to a form so there is no limit to the number of input boxes there can be. I have got a jquery autocomplete function that works fine if the input box is added by the server but the listener doesnt fire when the text box is added client side. As with all things this is part of a much bigger project and I only want to change the smallest possible part (add autocomplete to this text input box) MY QUESTION: is it even possible fo ra jquery listener to fire when the input box has been written client side after the page has loaded? Is there a way to "refresh" a listenerto find the new tag that have been added?
View 2 Replies
View Related
Jan 21, 2010
I've made a page to listen to The Dutch Top 2000 ever.. Example : [URL] After that I want my fewers/listeners to put a new youtube link to my database by giving input from my page. Example: [URL] For my database it is required that the input only 7fXaC07X5M8 instead of the complete link. [URL] My probem is how to handle the input in my form by javascript:
<td><input type="text" name="YourLink" size="256 maxlength="256" value="http://www.youtube.com/watch?v=7fXaC07X5M8&feature=player_embedded#"></td>
To a striped link :7fXaC07X5M8 what is accepteble for my database
View 4 Replies
View Related