SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Guru
    Join Date
    Jun 2004
    Location
    UK
    Posts
    605
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Aaaarrghh! Simple if else problem

    Hi,

    Can anyone see why this isn't working:

    Code:
    var feeRepayment = get_cookie('misc1');	// 1= immediate, 0 = deferred
    alert(feeRepayment);
    if (feeRepayment = 1) {
    	alert('immediate');
    }else{
    	alert('deferred');
    }
    The first alert outputs the cookie properly, either 1 or 0.

    However, the 'if' conditional always seems to think that the value is 1 - even when it is 0!?

    Can anyone see what the problem is?

    Thanks very much...

  2. #2
    Non-Member melancholic's Avatar
    Join Date
    Nov 2004
    Location
    Australia
    Posts
    447
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Code:
    if (feeRepayment = 1) {
    This single equals sign is an assignment operator not a test.
    You need the double equals sign to do a logical test.

    try:

    Code:
    if (feeRepayment == 1) {
    regards,

  3. #3
    SitePoint Guru
    Join Date
    Jun 2004
    Location
    UK
    Posts
    605
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Perfect, thanks. I knew it would be something silly!


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •