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

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • jayman9782
    New Member
    • Mar 2008
    • 10

    #1

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

    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:
    Code:
    <script language="javascript" type=text/javascript>
    //If the window is closed
    function doUnload(){
    if (window.event.clientX < 0 && window.event.clientY < 0)
    {
        var Division = '' + document.forms(0).txtDivisionCode.value + '';
        if (document.forms(0).txtScreen.value = 'Division'){		
             window.opener.location = '../Maintenance/Divisions.aspx';
        }
        else {
            UpdateAcctEditScreen(Division);
        }
    }
    }
    </script>
    ...
    <body onunload="doUnload()">
    The window.opener.l ocation 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.
  • pronerd
    Recognized Expert Contributor
    • Nov 2006
    • 392

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

    This is just setting the value of document.forms( 0).txtScreen.va lue to 'Division'
    Code:
    document.forms(0).txtScreen.value = 'Division'
    To test to see if the two values are equal it would need to be :
    Code:
    document.forms(0).txtScreen.value == 'Division'

    Comment

    Working...