Connecting Tech Pros Worldwide Forums | Help | Site Map

Javascript if... else... producing same no matter what the value

Newbie
 
Join Date: Mar 2008
Posts: 10
#1: Mar 24 '08
I'm working with ASP.NET 1.1 and I am attempting to compare the value of a textbox on the pages onunload event. The screen that is open is a pop-up screen that can be opened from links on two different pages. What i want to do is cause a post back to the form from which the pop-up screen originated.
Here is my code:
Expand|Select|Wrap|Line Numbers
  1. <script language="javascript" type=text/javascript>
  2. //If the window is closed
  3. function doUnload(){
  4. if (window.event.clientX < 0 && window.event.clientY < 0)
  5. {
  6.     var Division = '' + document.forms(0).txtDivisionCode.value + '';
  7.     if (document.forms(0).txtScreen.value = 'Division'){        
  8.          window.opener.location = '../Maintenance/Divisions.aspx';
  9.     }
  10.     else {
  11.         UpdateAcctEditScreen(Division);
  12.     }
  13. }
  14. }
  15. </script>
  16. ...
  17. <body onunload="doUnload()">
The window.opener.location routine works fine in that it sucessfully loads the Divisions form. However, it does this no matter what the value of the txtScreen textbox is. It seems the Javascript is not performing the if statement correctly. Any help is appreciated. Thanks.
Expert
 
Join Date: Nov 2006
Posts: 392
#2: Mar 24 '08

re: Javascript if... else... producing same no matter what the value


You need to use a double equals sign (==) in an if condition.

This is just setting the value of document.forms(0).txtScreen.value to 'Division'
Expand|Select|Wrap|Line Numbers
  1. document.forms(0).txtScreen.value = 'Division'
To test to see if the two values are equal it would need to be :
Expand|Select|Wrap|Line Numbers
  1. document.forms(0).txtScreen.value == 'Division'
Reply


Similar JavaScript / Ajax / DHTML bytes