Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / June 2006

Tip: Looking for answers? Try searching our database.

Javascript -> Applet: variable reset after method call from javascript?!

Thread view: 
mcdeveloper - 12 Jun 2006 12:54 GMT
Hi all,

I 've got this strange (?) problem. I call a method from javascript, setting a private member variable USERENTERED. Within the method, everything goes fine, if I print the variable it has changed. However, as soon as I use the variable in another method, it has changed back to its initial value (which is -1 in my case).

I don't see what I'm doing wrong, the variable is not local but a member variable. This is the method being called:

public void setUserEnteredValue(String x)
{       
       try
       {           
           double d = Double.parseDouble(x);
           int xPos = (int)((d * FACTOR) + MARGINLEFT - (SCALEMIN * FACTOR));
          
           this.USERENTERED = xPos;
           System.out.println("User entered" + USERENTERED);
                     
       }
       catch (NumberFormatException nfe) { System.out.println("failed to set user input, input is " + x ); }
}

If the variable is made static, it DOES change, but this is undesired because (of course) all other instances of the applet will have a changed variable. I'm not setting the variable elsewere. Morveover, I'm using this technique for other variables as well and I've got the same problem with those.

Any ideas?

MC.
mcdeveloper - 13 Jun 2006 09:34 GMT
Solved. Didn't have to do anything with Java, had to do with being stupid (calling wrong control, d'oh!)

MC
 Hi all,

 I 've got this strange (?) problem. I call a method from javascript, setting a private member variable USERENTERED. Within the method, everything goes fine, if I print the variable it has changed. However, as soon as I use the variable in another method, it has changed back to its initial value (which is -1 in my case).

 I don't see what I'm doing wrong, the variable is not local but a member variable. This is the method being called:

public void setUserEnteredValue(String x)
{       
       try
       {           
           double d = Double.parseDouble(x);
           int xPos = (int)((d * FACTOR) + MARGINLEFT - (SCALEMIN * FACTOR));
          
           this.USERENTERED = xPos;
           System.out.println("User entered" + USERENTERED);
                     
       }
       catch (NumberFormatException nfe) { System.out.println("failed to set user input, input is " + x ); }
}

 If the variable is made static, it DOES change, but this is undesired because (of course) all other instances of the applet will have a changed variable. I'm not setting the variable elsewere. Morveover, I'm using this technique for other variables as well and I've got the same problem with those.

 Any ideas?

 MC.


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.