JQuery :: For Loop Returns Same # Every Time In A Click Function?

Dec 2, 2010

I have a for loop which has a length of 8. It's meant to run through an array of objects and bind a click function to all of them. So the alert should run a range 0-7 but instead it returns 8 no matter which object is being clicked.

for (var j = 0; j < bubbleArray.length; j++) {
$('#icon' + j).bind('click',function() {
var icon = this.id;
this.diam = $(this).width();

[Code].....

View 3 Replies


ADVERTISEMENT

Time Function - Output Returns Nothing

Feb 21, 2010

I am trying to taking this embedded script
Code:
<SCRIPT LANGUAGE="JavaScript">
<!-- Begin
var strDay;
if ((now.getDate() == 1) || (now.getDate() != 11) && (now.getDate() % 10 == 1)) // Correction for 11th and 1st/21st/31st
strDay = "st ";
else if ((now.getDate() == 2) || (now.getDate() != 12) && (now.getDate() % 10 == 2)) // Correction for 12th and 2nd/22nd/32nd
strDay = "nd ";
else if ((now.getDate() == 3) || (now.getDate() != 13) && (now.getDate() % 10 == 3)) // Correction for 13th and 3rd/23rd/33rd
strDay = "rd ";
else
strDay = "th ";
document.write(dayName[now.getDay()] .....
// End -->
</script>
and turn it into a function called time.

XHTML Source
Code:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "[URL]">
<html xmlns="[URL]" xml:lang="en">
<head>
<title>Test</title>
</head>
<body>
<strong><script type="text/javascript">time()</script></strong>
</body>
</html>

Javascript Source
Code:
function time() {
var strDay;
if ((now.getDate() == 1) || (now.getDate() != 11) && (now.getDate() % 10 == 1)) // Correction for 11th and 1st/21st/31st
strDay = "st ";
else if ((now.getDate() == 2) || (now.getDate() != 12) && (now.getDate() % 10 == 2)) // Correction for 12th and 2nd/22nd/32nd
strDay = "nd "; .....

But when I do the out put returns nothing. Why this might be. I initially thought that I had the formattingsyntax wrong for the function it self but this doesn't seem to be. [URL]

View 7 Replies View Related

Get An Audible Click Sound File To Run Every Time The Function Runs

Apr 27, 2011

I have a self project I am exploring. I would like to play a simple sound file each time a function is run. The function runs every second, so, basically, I am just trying to get an audible click sound file to run every time the function runs. I do not know how to play a sound file thru javascript. Here is the code file thus far...

<html>
<head>
<title>Timer</title>
<link href="timer.css" rel="stylesheet" type="text/css" />
<embed src="click.wav" autostart=false hidden=true name="sound1" enablejavascript="true">
<script type="text/javascript">
var seconds = 0;
[Code]...

View 7 Replies View Related

JQuery :: Function Returns The Code Inside The Function?

Aug 29, 2011

I am having a strange problem with a javascript function that does not return the value but returns the code inside the function. My best guess is that I am incorrectly calling the function hasLandedOn()and jquery is interpeting it. Why is this happening? I highlighted the parts in red.-Tom ReeseThe following is returned NOT the variable imageName.

function hasLandedOn(){
var selectorLoc = $("#selector").offset();
var imageName = "";

[code]....

View 2 Replies View Related

Double Ajax Calls, Using $F The Second Time Returns Null

Feb 11, 2006

I'm using the $F of the prototype library to send data through the Ajax
Request. I'm having problems using the $F to reference fields sent
back through an original Request. My first request sends a form back
to the user in the type such as <input text name=foo> and at the bottom
of the returned form I have a second ajax call to send the fresh data
to the another script. The problem is that the new data in the form
cannot be referenced from $F. My question is how can I pass the new
data in the javascript to another Ajax call either by $F or by other
means?

View 3 Replies View Related

JQuery :: InArray Function Always Returns -1?

Nov 23, 2010

In Firebug when I rollover the SelectList variable it certainly looks like an array.

[Code]...

View 2 Replies View Related

JQuery :: Validate: Regex That Returns True Elsewhere Returns False Inside Validator Method

Oct 8, 2009

Either I'm having a really dim Friday, or something strange is going on. I'm trying to add a method to the Validator plugin, using the following regex:

[Code]....

View 1 Replies View Related

JQuery :: Loop And Ajax Call - Add 5 To The Variable 'paramdatastart' Each Time The #btn Is Clicked

Apr 8, 2010

I want to add 5 to the variable 'paramdatastart' each time the #btn is clicked. So when I click it first time the 'paramdatastart' will be 5 and next time it will be 10 andso onHow do I do that?

This is the code:

View 3 Replies View Related

JQuery :: Css() Function Returns Different Results On Different Browsers?

Jun 11, 2009

Today I've tried to create simple hover effect on a <div>: if the cursor is over the box, the background-image css property of the div is modified. On the HTML side, a <div> with an id:

<div id="round">Blah blah
</div>

View 3 Replies View Related

JQuery :: Get Xml Data Function Returns Undefined

Nov 22, 2011

I am trying to make a function that will return part of some xml data, but It keeps returning "Undefined" here is the function, with the call:

Code:

function getUserInfo(u, t) {
$.ajax({
type: 'GET',

[code]....

View 6 Replies View Related

Call Function In Script And Pass One Parameter To Function And Its Returns String Value?

Feb 15, 2012

I want to call java function in javascript.In which we pass one parameter to function and its returns String value which I want to display in alert message.

View 2 Replies View Related

JQuery :: Get And Ajax Function Returns Empty Response?

Sep 27, 2010

The goal is to change the source on the fly (as with a firefox extension webdev or another or even Greasemonkey) to add a link. Until then, easy does it work well. This link launches an application ajax jquery like:
$.get(...) or even $.ajax(...)

If I'm on [URL], added my link, I click and it works, I see the ajax request and pass my "alert ()" gives me the return of application. Great! But if I'm on a site other than mine (the url of the ajax request is [URL] while I'm at [URL] for example), the return of the ajax request is empty.

View 9 Replies View Related

JQuery :: Ajax Call Returns Some Internal Function

Jun 29, 2011

Clearly I am invoking this wrong.

[Code]...

View 1 Replies View Related

Recursive Function With For Loop, For Loop Is Breaking When Calling Itself

Jan 22, 2011

I have been looking at this code for two evenings now, and rewrote it 4 times already. It started out as jQuery code and now it's just concatenating strings together.

What I'm trying to do: Build a menu/outline using unordered lists from a multidimensional array.

What is happening: Inside the buildMenuHTML function, if I call buildMenuHTML, the for loop only happens once (i.e. only for 'i' having a value of '0'.) If I comment out the call to itself, it goes through the for loop all 3 times, but obviously the submenus are not created.

Here is the test object:

test = [
{
"name" : "Menu 1",
"url" : "menu1.html",
"submenu" : [

[Code].....

'Menu 2' and 'Menu 3' don't show up! I'm sure it's something small that I'm overlooking.

View 2 Replies View Related

Send A Loop Variable (i) To A Function Inside The Loop

Aug 4, 2011

I'm looking to send a loop variable (i) to a function inside the loop, but I can't seem to get it to use the value I want, it keeps making it a reference of i and therefore the function is always called using the last value of i rather than the one it was set with.

So if i have 5 Tabs then Tab 1, when clicked, should call DefaultTabClick(0) and so on rather than always using 4 for any of the tabs.

View 2 Replies View Related

Loop Working Once But Not A Second Time?

Oct 6, 2009

I have a form on my page that gets checked and verified with a bit of AJAX and then gets sent off if all is good, but I also created a quick little loop to verify that all the fields are still full and completed before sending the info off to the server officially .here is my test page for the loop that i have created.

PHP Code:

<html>
<head>
<script type="text/javascript">

[code]...

Now the loop works great if you test it by clicking on the button once but if you fill in a missing field and click the button ok then it doesnt work again ... how can i get it to work on every click ?

View 3 Replies View Related

JQuery :: Bind Click-event Via Loop?

Aug 6, 2010

I would like to substitute the following lines with a loop, such that I do not have to copy them countless times... (array stores jQuery-objects / with the $ in front)array[0].click(function() { someFunction(0); });

[Code]...

Can someone please explain the reason for this (I'm guessing the assignment only 'lives' during execution of the loop-cycle) and maybe suggest a way around it?

View 3 Replies View Related

JQuery :: Binding Click Event In A Loop?

Sep 20, 2010

I have a question that's probably basic javascript, but I can't find the answer.So if any of you can point me in the right direction?This is the problem:I want to loop through an array and in each iteration I want to bind a value from that array to a click event.I made a small example where I only bind the first iteration to a click event.

$(document).ready(function(){
var dummy=new Array();
dummy[0]=1;

[code]....

View 3 Replies View Related

JQuery :: Setting Click Event Functions In For Loop

May 16, 2009

I have a webpage that searches a database using a php script to search the database and a jQuery app on the page to retrieve the results and show them. So it works fine, but then I want to add page number buttons to allow the user to go to different "pages" of the results.So I have a DIV with the id of "page_buttons" and I use the following URL...I use the offset and the results per page like this in a MySQL query in the php script: SELECT .... LIMIT offset,resultsPerPage by the way.[code]

View 2 Replies View Related

Jquery :: Make List And Apply Click Event In One Loop?

Feb 5, 2010

Code JavaScript:
var listItems = "";
$.each(msg.d, function(index, value) {
listItems += "<li><a href='#' class='" + value.Availability + "' title='" + value.Time + "' >" + value.Time + " - " + value.Availability + "</a></li>"
});
 
var teeTimeLinks = $(listItems + 'li');
$.each(teeTimeLinks, function() {
var link = $(this).find('a');
link.bind('click', function(event) {
event.preventDefault(); //stop the link from going to href
TeeTimeSelected(this);
});
});

The above code works. BUT, msg.d returns 80 objects. We then loop through it and make our list items. AND then we loop through it again and apply the click event. How can this be optimized into one loop?

View 18 Replies View Related

RotateSwitch Function - Value Incorrectly Always Returns One

Sep 4, 2010

I have four images:
Code:
<div class="main_view">
<div class="window">
<div class="image_reel">
<a href="#"><img src="images/1.png" alt="" /></a>
<a href="#"><img src="images/2.png" alt="" /></a>
<a href="#"><img src="images/3.png" alt="" /></a>
<a href="#"><img src="images/4.png" alt="" /></a>
</div></div>

When rotateSwitch() is called on launch, it assigns the second image to the $active variable (given that the first image was given active class in beginning of script). Then rotate() function is called and we get 1 (2-1) and then multiply by imageWidth. Now the second time the rotateSwitch() function is called, we should get 2 (3-1), but the alert still only returns 1 and the fourth time it only returns 1 as well:
Code:
$(document).ready(function(){
$(".paging").show();
$(".image_reel img:first").addClass('active');
var imageWidth = $(".window").width();
var imageSum = $(".image_reel img").size();
var imageReelWidth = imageWidth * imageSum;

$(".image_reel").css({'width' : imageReelWidth});
rotate = function(){
var triggerId = $active.attr('src').substring(7,8);
var image_reelPosition = (triggerId - 1) * imageWidth;
alert('the value is ' + triggerId);
$(".image_reel img").removeClass("active");
$active.addClass("active");

$(".image_reel").animate({
left: -image_reelPosition
}, 500);
};
rotateSwitch = function(){
play = setInterval(function(){
$active = $(".image_reel img.active").next();
if ($active.length === 0){
$active = $('.image_reel img:first');
}
rotate();
}, 7000);
};
rotateSwitch();
});

View 2 Replies View Related

Execution Of Function Bar - Returns Undefined

Dec 12, 2011

Suppose we have following javascript codes: Case 1.
var foo = function (){
var x = "hello";
var bar = function () {
alert(x);
} return bar;
} var bar_ref= foo();
document.write(bar_ref()); // it pops up "hello" and print-outs "undefined".

If we modified above code slightly, shown as follow: Case 2.
var foo = function (){
var x = "hello";
var bar = function () {
alert(x);
} return bar();
} var bar_ref= foo();
document.write(bar_ref()); // it only pops up "hello".

As you can see, Case 2 modified the return value from "return bar" to "return bar()," which won't cause the "undefined" output. To me, it looks like when the JS interpreter executes the line "bar_ref();" it triggers the execution of function "foo", besides both "return bar" and "return bar()" do the same job which is to execute function body of "bar".

The only difference is that after the execution of function bar, its function body does not exist anymore, so when the interpreter executes the line "return bar;" it follows the function identifier "bar" and ends up with "undefined". This is why the Case 1 gives us "undefined", but I am not quite clear about why the Case 2 can trace down to the function body of "bar". Do you have any ideas about such difference outputs?

View 3 Replies View Related

String.Length Function Returns Undefined?

Mar 27, 2011

When I run the following code, the .Length function returns "undefined."

var strTest = 'test';
alert(strTest.Length);

Using the typeof function, I know that JS is treating the variable as a string.

View 4 Replies View Related

Show Location - Function Returns Undefined

Jul 27, 2011

Here is a code I use to calculate distance b//w 2 places using google api. It works perfectly and shows the results in the html but when I add a return statement at the end of the function showlocation() it returns undefined.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "[URL]">
<html xmlns="[URL]">
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8"/>
<meta name="robots" content="noindex,follow" />
<title>Calculate driving distance with Google Maps API</title>
<script src="[URL]" type="text/javascript"></script>
<!-- According to the Google Maps API Terms of Service you are required display a Google map when using the Google Maps API. see: [URL] -->
<script type="text/javascript">
var geocoder, location1,addr1,addr2, location2, result1,gDir;
function coolAl(add1,add2) {
addr1=add1;
addr2=add2;
var result= return initialize();
showLocation();
alert(result);
} function initialize() {
geocoder = new GClientGeocoder();
gDir = new GDirections();
GEvent.addListener(gDir, "load", function() {
var drivingDistanceMiles = gDir.getDistance().meters / 1609.344;
var drivingDistanceKilometers = gDir.getDistance().meters / 1000;
result1=location1.address + ' (' + location1.lat + ':' + location1.lon + ')/' + location2.address + ' (' + location2.lat + ':' + location2.lon + ')/' + drivingDistanceKilometers + ' kilometers';
document.body.innerHTML=result1;
return drivingDistanceKilometers;
});
} function showLocation() {
geocoder.getLocations(addr1, function (response) {
if (!response || response.Status.code != 200) {
alert("Sorry, we were unable to geocode the first address");
} else {
location1 = {lat: response.Placemark[0].Point.coordinates[1], lon: response.Placemark[0].Point.coordinates[0], address: response.Placemark[0].address};
geocoder.getLocations(addr2, function (response) {
if (!response || response.Status.code != 200) {
alert("Sorry, we were unable to geocode the second address");
} else {
location2 = {lat: response.Placemark[0].Point.coordinates[1], lon: response.Placemark[0].Point.coordinates[0], address: response.Placemark[0].address};
gDir.load('from: ' + location1.address + ' to: ' + location2.address);
}});}});}
</script></head>
<body onload="coolAl('pune','mumbai')">
</html>

View 9 Replies View Related

JQuery :: Calling The Time And Hiding It On Click (not Working)

Aug 18, 2011

I am trying to show the time and when you click it I want it to go away. But its not working.

<script type="text/javascript">
var date=new Date();
var time=date.getHours();

[Code].....

So I dunno what im doing wrong but when I do this the page is blank.

View 4 Replies View Related

Jquery :: Adding Input Values Each Time On Top When Click?

Feb 25, 2010

I am trying to write this code which the value in the input field can be added on top each time when you get the value from links,

Code:
$(document).ready(function(){
autofill();

[code]....

View 2 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved