Results 1 to 5 of 5

Thread: Trying to insert page in a div with .load on jquery

  1. #1
    Join Date
    Nov 2016
    Posts
    23
    Thanks
    7
    Thanked 0 Times in 0 Posts

    Default Trying to insert page in a div with .load on jquery

    I am trying to insert a page in a div after a button click, the buttons get there text from a database.

    This is the php part

    PHP Code:
    <?php    
     
       
    $test 
    mysql_query("SELECT item FROM items");
     

    while (
    $row mysql_fetch_array($test)){
        echo    
    '<a href="" align-left = 10px;><div class="item">'.$row['item'].'</div></a>'
        

    }
        

    ?>

    Jquery

    HTML Code:
    <script type="text/javascript">
          
             
     $(".keuze").on('click', '.item', function(){
      
                
        var $deel = $(this).text();
         
      if ( $deel == "Statuten"){
        
            
        $('#uitkomst').load('statuten.php');
        
    }
       
     
    });   
          
    
    </script>
    
    
    <div id="uitkomst"></div>       /**** Where I want the page to load ****/
    Statuten is the value of the first button.

    When I test with alert($deel); it gives the right value but on click it shows the page to insert for about 1 second, sometimes it works when I dubble click.

    I am searching the web for a week now and cannot find the answer I need.

    any ideas??

    it's hard to explain because of my poor english and i am a newbie to jquery and php.

  2. #2
    Join Date
    Oct 2016
    Posts
    9
    Thanks
    0
    Thanked 2 Times in 2 Posts

    Default

    Hey did you try this? Let me know if this doesn't work.
    Code:
    $(document).on("click",".item", function() {
      var $deel = $(this).text();  
       if ( $deel == "Statuten"){  
         $('#uitkomst').load('statuten.php');
       }
    });

  3. The Following User Says Thank You to rubyOnPails For This Useful Post:

    Bicklo (11-26-2016)

  4. #3
    Join Date
    Nov 2016
    Posts
    23
    Thanks
    7
    Thanked 0 Times in 0 Posts

    Default

    Thank you for your reply, still the same problem showing the loaded page for 1 second on click and then nothing.

    I am sure it has to do with php but don't know what.

  5. #4
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    One problem is that the link is executing normally. An href of "" means reload the page. To stop that:

    Code:
    $(document).on("click",".item", function(e) {
      var $deel = $(this).text();  
       if ( $deel == "Statuten"){  
         $('#uitkomst').load('statuten.php');
         e.preventDefault();
       }
    });
    which will prevent the link from executing only when loading the external page. If you want all .item links to not fire normally, do it like so:

    Code:
    $(document).on("click",".item", function(e) {
      var $deel = $(this).text();  
       if ( $deel == "Statuten"){  
         $('#uitkomst').load('statuten.php');
       }
       e.preventDefault();
    });
    There could still be other problems.
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  6. The Following User Says Thank You to jscheuer1 For This Useful Post:

    Bicklo (11-26-2016)

  7. #5
    Join Date
    Nov 2016
    Posts
    23
    Thanks
    7
    Thanked 0 Times in 0 Posts

    Default

    Thank you sir, you did it, a 14 day headache finaly over.

    Thank you so much!!

Similar Threads

  1. Multi-zoom help: load magnified area on page load
    By tbarmann in forum Dynamic Drive scripts help
    Replies: 1
    Last Post: 06-23-2013, 03:23 AM
  2. Replies: 2
    Last Post: 01-31-2012, 03:57 PM
  3. Replies: 9
    Last Post: 09-07-2011, 08:25 PM
  4. jQuery extenal page load
    By lazyserv in forum Looking for such a script or service
    Replies: 0
    Last Post: 10-06-2010, 04:13 AM
  5. How to Insert JQUERY in PHP ZENCART
    By desaitejas in forum PHP
    Replies: 0
    Last Post: 03-20-2009, 08:58 AM

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
  •