Using A Loop Variable In Function Call?

Apr 6, 2011

i'm having trouble with some of my codes.i've been trying to put variables in function calls parameters, but it just does not work.
for example, if I try to do sth like this:

Code:
//a function that creates page numbers based on number of pictures that can be shown on the page
function MenuBar() {
pageSpan = [document.createElement('span')];[code]....

when i try to run it, it won't work.what i'm trying to do is that every time the loop runs, the "onclick" event of the created span will be the value of the loops "x" variable -1, and the value of x variable.meaning, for every new span, the parameters in the showImage() function are different.

Code:
pageSpan[1].onclick = function () { showImages(0, 1) };
pageSpan[2].onclick = function () { showImages(1, 2) };
pageSpan[3].onclick = function () { showImages(2, 3) };
pageSpan[4].onclick = function () { showImages(3, 4) };
pageSpan[5].onclick = function () { showImages(4, 5) };

View 3 Replies


ADVERTISEMENT

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

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

Call A Function Inside A Loop?

Dec 27, 2010

I want to call a function inside a loop of an array but when I run it, it is only reaching the function the first time.

for (i in qMedia) {
writeMedia(qMedia[i].name, qMedia[i].format);
}

Even when I tried to call it outside the loop multiple times, it only executed once.

writeMedia(qMedia[0].name, qMedia[0].format);
writeMedia(qMedia[1].name, qMedia[1].format);
writeMedia(qMedia[2].name, qMedia[2].format);

I know that each of the objects in the array have data because I tried to run each one of the lines above separately without calling the other two and it worked fine.

View 2 Replies View Related

Call Script Function Inside A For Loop?

Apr 26, 2010

I'd like to ask how can i ask for a function inside a for loop , if i remove the loop the code works fine but i need it for 10 rows .here is the code...

View 3 Replies View Related

Ajax :: Unable To Call Function In A Loop / Enable This?

Jun 29, 2009

I am trying to track progress of a database operation . and want to display percentage progress on page asynchronously.

Process.jsp - In this i used javascript to call ajax function continuously which returns percentage progress. My Code is ...

View 1 Replies View Related

For Loop Passing Variable To Function?

Feb 10, 2010

I'm trying to make it so when you click a cell in a table it runs a function based on the value within that cell. With the current code, no matter what cell is clicked, the alert box displays the same number, which is the last number in my array. The variable, princ, is just being overwritten rather than writing code to each the cell with the proper value.

for(i=0;i<=3;i++){
document.writeln('<tr>');
document.writeln('<th>'+(periodArray[i])+'</th>');

[code]....

View 3 Replies View Related

JQuery :: CYLCE - Loading Text Portions + Defining A Loop + Function Call On The Specific Slide?

Feb 19, 2011

1.In ZZZ.html i have a long list of text items formated like this:

<div="part1">
<span > <h3 >AAA</h3><h4>BBB</h4></span>
<span > <h3 >CCC</h3><h4>DDD</h4></span>

[code]....

In another document i made some buttons to change slideshow content by loading sections id to

<div id="cyc" class="slide"></div>
using function:
$('#cyc').load("ZZZ.html #part1");
etc...

Text loaded, but the slideshow didn`t work

2.How can i loop specific range of slides ( and make it modifiable with some "range selector" in browser) ?

3.Is it possible to trigger some event on the desired slide number ?for example:

on slide 3 - play sound
on slide 6 - display message
on slide 15 - go through slides 10-15 four times

[code]....

View 6 Replies View Related

Using A Variable As A Function Call?

Feb 21, 2010

how can I call a function by using the value of a variable name?i.e.

Code:
var str = "function_name";
// call 'function_name' by using its 'str' alias

View 7 Replies View Related

JQuery :: Cannot Get Variable Inside Loop Back To Original Function

Oct 22, 2009

I'm having some problem with return value for a function. I'm trying to access google blogger's API to display blog entries on my site. I'm doing this through JQuery and requesting a JSON response. Everything seems to work ok, but I want to access the link for the blog entry. This is a subset of the "entry" object.

It's structured like this:
Entry:
title,
content,
link:
rel,
type,
href,
rel,
type,
href,

I want to get the link where the "link.rel == "self". To do this I have to loop through the link object (5 times). The loop and conditional statement works correctly, but I can't get the variable inside this loop back to my original function.

I have this code:
$.each(data.feed.entry, function(i, entry){
$.each(entry.link, function(j, link){
if(link.rel == "self"){
var postlink = link.href;
alert("link : " + postlink);
return postlink;
}});
alert(postlink);
});

View 2 Replies View Related

Call Nested Function From Variable

Nov 6, 2011

I'm having trouble calling a function using a variable, from within a parent function. For instance:

function parent(){
function child(){
console.log("It worked")[code]....

That results in "TypeError: 'undefined' is not a function (evaluating 'window[test]()')"

View 6 Replies View Related

Call A Variable From A Specific Function In Another Outside?

Aug 20, 2009

how do i call a variable from a specific function in another function outside the first one?

View 4 Replies View Related

Passing Variable In Function Call?

Mar 22, 2010

I can call a function from a hyperlink as so:

<A HREF="javascript:go()">+ Add Text</A>

but how do I pass a variable to the function in this hyperlink?

View 2 Replies View Related

Function Name In Variable Combined With 'call'?

Jan 12, 2010

I have a situation in which the function to be called is stored in a variable.

Code:
function Test() { this.v = 10 }
function abc(o) {
alert( this.v + " and " + o) ;[code].....

View 11 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

Global Variable Glitch - Can Only Access The Variable On The Second Call

Dec 9, 2011

I am simply trying to use a global variable in javascript, but can only access the variable on the second call. I can't find anything that relates to this through my searches. My application is supposed to query the server for XML that tells me which years and months are available to put into combo boxes. I want to store this xml in a global variable to access it later.

[Code]....

View 6 Replies View Related

Using A For Loop To Call An Image?

Nov 21, 2011

I am trying to use a for loop to call images of custom text. For example, I have images named uppera.png and lowera.png for a custom font. I need the image of the letter to show up as they type into a text area, but also have backspace work correctly to delete the last image added. Here is the code I have thus far:

<script type="text/javascript">
function callimage() {
var chars = document.getElementById('userinput').value.split("");[code]....

When I test this out it takes the previously entered text and adds it to the new text and combines them. For instance if you entered "a" it would show up as "a"; if you entered "a" again it would show up as "aaa" and then "aaaaaa" and so on. Also, it will add the existing characters again if any key is pressed, like just shift. I think I would need to write an else statement to fix that part, but I don't know what to put there, either.

View 14 Replies View Related

Function Call With Quotes Inside Another Function Call?

Feb 11, 2006

<button onClick="return popup('<span onClick='selectShape(1, 1, 1)'>test<span>');" tabindex=&#393;' onFocus="setFocusColor(0,3)">....</button>
This will work perfectly, but as soon as I need to pass Strings inside the selectShape function, I get stuck.

So the question is, how can I create the following and have it working

......selectShape(2, 'Tricky', &#3940;x5°').....

View 1 Replies View Related

JQuery :: Call To FadeIn() Within A Loop Causing Page To Scroll Up?

Feb 18, 2010

I am using a timer to fadeOut and fadeIn some articles such that 5 articles are displayed in rotation.However, for some reason the call to fadeIn or fadeOut is causing the page to change it's y scroll position. If I am currently at the bottom of the page, the fadeIn call causes the page to scroll up.

View 2 Replies View Related

Using Variable In A Loop?

Dec 15, 2009

I have a lot of variables (lab0, lab1, lab2, ...). How can I use these vaiable in a loop. Javascript thinks it is a variable 'labi'.

for ( var i=0;i<10; i++ )
{
f1.path.op[i].value = f1.labi.value;
}

[code]...

View 6 Replies View Related

Store Expression In Variable And Use It In Loop

Jan 28, 2011

The following loop works:
Code:
<html>
<body>
<script type="text/javascript">
var i=0;
for (i=0;i<=5;i++) {
document.write("The number is " + i);
document.write("<br />");
}
</script>
</body>
</html>

But the following doesn't:
Code:
<html>
<body>
<script type="text/javascript">
var i=0;
var x="i=0;i<=5;i++"
for (x){
document.write("The number is " + i);
document.write("<br />");
}
</script>
</body>
</html>
I'd just like to create a simple variable.

View 5 Replies View Related

JQuery :: Update Variable In Html From Within A For Loop

May 22, 2011

So i have this code

[Code]...

and what i want to happen is the variable number to update so that the user can see how many times the loop has run in real time. If you have to change the code around for it to work that is fine as i can adapt my code to it And obviously this script has no real function to it, it is just an example to show the jist of my actual code(don't think you want to look at a few hundred lines now do you)

View 3 Replies View Related

Write A For Loop Up To 100 With Multiples Of 3 And 5; Every Multiple Variable?

May 13, 2011

Trying to write a for loop up to 100 with multiples of 3 and 5; every multiple variable will need to have a name instead of a number?

View 5 Replies View Related

Dynamically Create Variable Names From A Loop?

Feb 11, 2010

I am working on a project where I need to redo the same thing with new variable names

Code JavaScript:
var paper1 = new Raphael('img1', 500, 500);
c1 = paper1.rect(0, 0, 50, 20, 5);
var paper2 = new Raphael('img2', 500, 500);
c2 = paper2.rect(0, 0, 50, 20, 5);

I would like to be able to do this with a for loop. So in the above example I would want paper+i, img+i, and c+i was trying eval("paper"+i) but didn't work.

View 1 Replies View Related

Declare A Variable Inside A Function - Returns White Space - Not Variable Value

Aug 17, 2010

I am trying to declare a variable inside a function and use it later on in my code... but it just already returns white space... i.e. not variable value. I am setting it within this function:

function show_video1(){
document.getElementById('video1').style.display="block";
var video1Name = "Education World News (Part 1)";
document.getElementById('video2').style.display="none";
document.getElementById('video3').style.display="none";
document.getElementById('video4').style.display="none";
[Code]...

and trying to call it later on with this: <script type="text/javascript">document.write(video1Name)</script> It might be worth noting that each one of my 11 videos will hace a different name.

View 13 Replies View Related

JQuery :: How To Call Session Variable

Feb 22, 2011

I am trying to reference a session variable inside some JQuery code. Theseexamples below arewhat I am using currently just to try and see if I can get something to display and nothing shows up.[code]Just to make sure an alert works, I threw in a alert("hi"); which works fine. It is when I try to write out the session variable it fails.

View 8 Replies View Related







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