Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    Regular Coder
    Join Date
    Dec 2006
    Posts
    417
    Thanks
    168
    Thanked 1 Time in 1 Post

    JQuery Listener not Listening

    I am trying to click an input type checkbox.. when clicked an AJAX call is performed. I have a listener set up but nothing fires ... firebug also shows nothing.

    Code:
    Code:
        <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
        <script type="text/javascript">
        $(document).ready(function() {
    alert('test');
    if ($('#profile_visible:checked').val() !== null) {
    
            $.ajax({
              url: 'inc/profileVisible.php',
              success: function(data) {
                $('#resultProfileVisible').innerhtml="success";
                alert('Load was performed.');
              }
            });
    }
        }
        </script>

    ....and in the body of the document:

    Code:
        <form method="post" action="profile/<?php echo $_SESSION['usern']; ?>/settings">
        <p><input type="checkbox" id="profile_visible" name="profile_visible" /> Show Profile<span id="resultProfileVisible"></span></p>
    </form>

  • #2
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,978
    Thanks
    4
    Thanked 2,659 Times in 2,628 Posts
    I'm curious as to why you believe this is a PHP issue? From what I see, this is entirely an issue with your JQuery.

  • Users who have thanked Fou-Lu for this post:

    Bobafart (01-28-2012)

  • #3
    Regular Coder
    Join Date
    Dec 2006
    Posts
    417
    Thanks
    168
    Thanked 1 Time in 1 Post
    I agree but there isn't a jQuery forum....

  • #4
    Supreme Master coder! _Aerospace_Eng_'s Avatar
    Join Date
    Dec 2004
    Location
    In a place far, far away...
    Posts
    19,291
    Thanks
    2
    Thanked 1,043 Times in 1,019 Posts
    Quote Originally Posted by Bobafart View Post
    I agree but there isn't a jQuery forum....
    Oh really? http://www.codingforums.com/javascript-frameworks/

    The problem is that you don't in fact have a "listener" on your checkbox. All you did was check for the value when the page loads but nothing else. You need to use .click
    Code:
    #profile_visible.click(function(){if ($(":checked").val() !== null) {
    
            $.ajax({
              url: 'inc/profileVisible.php',
              success: function(data) {
                $('#resultProfileVisible').innerhtml="success";
                alert('Load was performed.');
              }
            });
    }});
    You also need ); just after the last } in your document ready call. You should be using .html not .innerHTML. FYI innerhtml isn't valid.
    Last edited by _Aerospace_Eng_; 01-28-2012 at 06:44 PM.
    ||||If you are getting paid to do a job, don't ask for help on it!||||

  • #5
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,978
    Thanks
    4
    Thanked 2,659 Times in 2,628 Posts
    Quote Originally Posted by Bobafart View Post
    I agree but there isn't a jQuery forum....
    Not an individual one no, AE pointed out the JS Frameworks forum which is more inline with the actual problem. I'm not sure why you thought that PHP is the next best forum when you couldn't find the specific one though; javascript forum would have been the better option.
    Moving from PHP forum to Javascript frameworks.


  •  

    Tags for this Thread

    Posting Permissions

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