dcsimg
www.webdeveloper.com
Results 1 to 2 of 2

Thread: JQuery.. why is this code not working? (return: false;)

  1. #1
    Join Date
    Aug 2006
    Posts
    255

    JQuery.. why is this code not working? (return: false;)

    I have some some JQuery code that is attached to an image's click event. The image has a href value attached to it. That part works well. When the button is clicked, the JQuery does an AJAX call to another script, which returns a value, and sets that value to variable called 'data'. That part works well. The function then checks if the value (a string) is 'TRUE' or 'FALSE'. That part works well.

    What I then want to do is, if the value of 'data' is 'FALSE', then I want to prevent the user from leaving the page (ie, 'return false;', and override the href on the image). If the value of 'data' is 'TRUE', then I want the user to sail on through to the next page (ie, just don't do a 'return false'; ).

    This fails:

    HTML Code:
    <script type="text/javascript">
    $(document).ready(function() {
    
        $('.print_btn').click(function() {
        $.get('some_script.php',
              { val1 : "2", val2: "30" },
              function(data) { if (data == 'TRUE') { alert ('TRUE'); } else { alert ('FALSE'); return false; } },
              'text');
      });
    
    });
    </script>
    And this fails:

    HTML Code:
    <script type="text/javascript">
    $(document).ready(function() {
    
        $('.print_btn').click(function() {
        $.get('some_script.php',
              { val1 : "2", val2: "30" },
              function(data) { if (data == 'TRUE') { alert ('TRUE'); } else { alert ('FALSE'); } },
              'text');
      });
      if (data == 'FALSE') {
        return false;
      }
    
    });
    </script>
    HELP?

  2. #2
    Join Date
    Oct 2006
    Posts
    939
    true and false are not always string.
    Leave off the quotes when setting and retrieving
    or to cut confusion set true as 1 and false as 0 without quotes

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles