473,387 Members | 1,542 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,387 software developers and data experts.

refresh variables using other function

18
Hello,

I need a function to alter some variables of other function, how can I do that?

ex:
Expand|Select|Wrap|Line Numbers
  1. function1 ()
  2. {
  3.     var a = 7;
  4.     var b = 25;
  5.     var c;
  6.     var d;
  7.  
  8.     function2 (a, b); //Does a bunch of tests and refreshes c and d values
  9.     alert(c); // --> should be 2 
  10.     alert(d); // --> should be 1
  11. }
  12.  
  13. function2 (a, b)
  14. {
  15.     if (a < 5)
  16.     {
  17.        this.c = 0;
  18.     }
  19.     elseif (a > 10)
  20.     {
  21.        this.c = 1;
  22.     }
  23.     else
  24.     {
  25.        this.c = 2;
  26.     }
  27.  
  28.     if (b < 10)
  29.     {
  30.         this.d = 0;
  31.     }
  32.     elseif (b > 20)
  33.     {
  34.        this.d = 1 ;
  35.     }
  36.     else
  37.     {
  38.         this.d = 2;
  39.     }
  40. }
  41.  
  42.  
Putting c and d as global will solve the problem I think , but I would prefer to have these inside function1.

I tried var f = new function2(a,b) and then accecing by f.c and f.d but when alerting the value , it comes "undefined"


Any ideas?

Thanks in advance,
Nibbus
Jan 28 '08 #1
3 2308
acoder
16,027 Expert Mod 8TB
c and d are private variables. Unless the function is defined within the object function, it can't access them.
Jan 28 '08 #2
Nibbus
18
I worked it around by removing var c and d from function1.
Don´t know if it´s working in the same way, but at least show´s me c and d values using objf2.c and objf2.d ...


Thank you
Jan 30 '08 #3
gits
5,390 Expert Mod 4TB
only for you to mention :) that with that solution you create var c and d implicitly in the global scope ... so after setting them you could access them as global variables ...

kind regards
Jan 30 '08 #4

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

Similar topics

9
by: Mark | last post by:
I have a working PHP/MySQL application used for data entry. The data entry screen includes a "Save" button. The PHP code for this button looks like this: if (isset($_POST)) { if ($_POST ==...
43
by: dan baker | last post by:
I have a page that gets loaded with a meta-refresh hardcoded so that a few things on the page get updated. its kind of a fake chat board. anyway, what I need to do is turn off the meta-refresh once...
0
by: Marcus | last post by:
Hello! I'm buildning a webpage in ASP.NET using Visual Basic. The page contains a datagrid, a dropdownlist, some textboxes and a couple of buttons. The datagrid displays barcodes from a table...
4
by: John | last post by:
I get the feeling this is a pretty classic problem, but I'm a bit of an uber newber. Apologies! Products page, user enters a quantity and clicks one of my "Add to Cart" buttons, which bubbles up...
17
by: Jim Little | last post by:
Hello, I'm driving myself crazy either because I'm missing something about ASP.NET, or what I'm trying to do simply can't be done. First, I am not using session variables to track state. My...
9
by: TCORDON | last post by:
I have a user control that contains 2 image buttons, when you click one of them, both must change the image source, the thing is that the first time you click any one of them the page appears to do...
2
by: Robert | last post by:
I am trying to give the user dynamic search capabilities to select almost any record in the database from criteria they select. Everything seems to work except when I open the display form to...
3
by: Ned Balzer | last post by:
Hi all, I posted this question some time ago in an earlier thread but so far I still don't have an understanding of why this is happening or what I can do to fix it. I use Session variables,...
10
by: markwalker84 | last post by:
Hello everyone! Got a bit of a problem... Two of the panels on my program contain a number of check boxes. The exact number of which is determined by a pair of variables. I have recently...
29
by: canabatz | last post by:
Hello , i got this code that works great , now i want to have it refresh every 4 seconds , where can i put the timer to do that? i realy need help!! thanx!! <script type="text/javascript">...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
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
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.