473,386 Members | 1,883 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

static variable in xajax?

18
I want to use static variable in xajax but always, it executes only one time.. When i call again, value of static variable isn't changing

how can i fix the problem? or how can i use static variable in xajax?
Aug 2 '07 #1
7 2522
pbmods
5,821 Expert 4TB
Heya, afraze.

JavaScript doesn't have static variables.

Instead, you can create a global variable, or if you are using a class that you created, you can declare a private variable in the class' scope and reference it in the method.

Have a look at this article.
Aug 2 '07 #2
afraze
18
hi i just want to do this:

here is my code sample:
[PHP]<?php
//xajax definiton
//in this part i have a xajax function that name is GetSelectedIndex
function test()
{
static $i = 0;
$i = $i + 10;
return $i;
}//this is php function

function GetSelectedIndex($selectedIndex)
{
......
......

$abc = test();
...
}

?>
[/PHP]

So my first try $i equals 10 but if i call again xajax function's GetSelectedIndex
$i is not counting..

i think my question is clear now :)

or should i ask this question in php forum?
Aug 3 '07 #3
hi i just want to do this:

here is my code sample:
[PHP]<?php
//xajax definiton
//in this part i have a xajax function that name is GetSelectedIndex
function test()
{
static $i = 0;
$i = $i + 10;
return $i;
}//this is php function

function GetSelectedIndex($selectedIndex)
{
......
......

$abc = test();
...
}

?>
[/PHP]

So my first try $i equals 10 but if i call again xajax function's GetSelectedIndex
$i is not counting..

i think my question is clear now :)

or should i ask this question in php forum?
Hi,
When ever the test function is called i is initialised to zero and then its incremented to ten.

In the first call i is zero and u can see i is incremented.
In the second call i is already 10 and when u call test.. I is set to 0 and again incremented to 10 so u cant feel the change..

kind regards..
Aug 3 '07 #4
afraze
18
newlearner,

i know but $i is a static variable, so when i try to use this function( test() ) in a php file.. It counts 10 by 10...

The problem is that it is not counting with xajax tech..
Aug 3 '07 #5
pbmods
5,821 Expert 4TB
Heya, afraze.

When you load the script, $i gets reinitialized. The only way to save the value of $i in this case is to use a $_SESSION variable.
Aug 3 '07 #6
afraze
18
pbmods,

thnks so much, i tried $_SESSION variable and, i got it. :)
Aug 3 '07 #7
pbmods
5,821 Expert 4TB
Heya, afraze.

pbmods,

thnks so much, i tried $_SESSION variable and, i got it. :)
Glad to hear you got it working! Good luck with your project, and if you ever need anything, post back anytime :)
Aug 3 '07 #8

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: Datta Patil | last post by:
Hi , #include<stdio.h> func(static int k) /* point2 : why this is not giving error */ { int i = 10 ; // static int j = &i ; /* point 1: this will give compile time error */ return k; } /*...
9
by: AnandRaj | last post by:
Hi guys, I have a few doubts in C. 1. Why static declartions are not allowed inside structs? eg struct a { static int i; }; Throws an error ..
28
by: Dennis | last post by:
I have a function which is called from a loop many times. In that function, I use three variables as counters and for other purposes. I can either use DIM for declaring the variables or Static. ...
6
by: Vladislav Kosev | last post by:
I have this strange problem now twice: I am writing this relatevely large web site on 2.0 and I made a static class, which I use for url encoding and deconding (for remapping purposes). This static...
55
by: Zytan | last post by:
I see that static is more restricted in C# than in C++. It appears usable only on classes and methods, and data members, but cannot be created within a method itself. Surely this is possible in...
10
by: Pramod | last post by:
Hello to all of you, I want to know that what's the use to create static object. Thanks You Pramod Sahgal
9
by: pplers | last post by:
I need some help. I want to make a search engine using Ajax, so i came across XAjax. And also tried AdoDB, for the pager. So, here it is: <?php require_once("xajax/xajax_core/xajax.inc.php");...
3
by: Richard K Miller | last post by:
Here's an OOP question that perplexes me. It seems PHP doesn't treat static variables correctly in child classes. <?php class ABC { public $regular_variable = "Regular variable in ABC\n";...
1
by: clzdl | last post by:
hi,i hope you can help me ! need your help! i find my refreshContent function can't be invoked . <?php require_once( 'Config/Config.inc.php'); ...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.