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 3 of 3
  1. #1
    Regular Coder
    Join Date
    Jun 2006
    Location
    UK
    Posts
    911
    Thanks
    302
    Thanked 2 Times in 2 Posts

    Question jQuery: Fetch Button Value.

    ok, Let me be as simple as I can with my question.

    I have an index.php page.

    Code:
    <HTML>
    <head>
    <TITLE>Welcome</TITLE>
    <script type="text/javascript" src="jquery.js"></script> 
    <script>
    	$(document).ready(function(){
    	$("#populate_tables").load("ajax.php?id=10");
    	});
    </script>	
    </head>
    
    
    <div id="populate_tables"></div>
    
    </html>
    The index.php loads all the information in the <div id="populate_tables"></div> tag when the page loads. This part works fine.


    Now, Lets see the code for ajax.php

    PHP Code:
    <?php $id =$_GET['id'];     
    $attachments mysql_query("select * from tbl where id=$id order by id desc");
             
    $num_rows count($attachments);
             
    ?>
            <table width="50%" border="1" cellspacing="0" cellpadding="3" class="border" style="border-collapse:collapse">
            <?php 
            
    if($num_rows>0){
                for(
    $x=0;$x<$num_rows;$x++){?>
          <tr>
            <td><input type="submit" id="att_del" name="att_del" value="<?php echo $attachments[$x]['id'];?>" /></td>
          </tr>
          <?php }//end for loop
          
    }else{//ifelse condition
          
    ?>
          <tr>
          <td align="center">No Attachments</td>
          </tr>
          <?php
          
    }//end else
          
    ?>
        </table>
    Everything works well so far.

    Lets go back to the index.php page

    When the list loads under the <div id="populate_tables"></div> tag, and when I click on the buttons (att_del), it should alert me with their button value.

    Please help.


    Thanx

  • #2
    Senior Coder shyam's Avatar
    Join Date
    Jul 2005
    Posts
    1,563
    Thanks
    2
    Thanked 163 Times in 160 Posts
    add a callback
    Code:
    <HTML>
    <head>
    <TITLE>Welcome</TITLE>
    <script type="text/javascript" src="jquery.js"></script> 
    <script>
    	$(document).ready(function(){
    	$("#populate_tables").load("ajax.php?id=10", '', function() {
    		$('#att_del').click(function() { alert($(this).value); });
    	});
    </script>	
    </head>
    
    
    <div id="populate_tables"></div>
    
    </html>
    You never have to change anything you got up in the middle of the night to write. -- Saul Bellow

  • Users who have thanked shyam for this post:

    phantom007 (09-09-2008)

  • #3
    Regular Coder
    Join Date
    Jun 2006
    Location
    UK
    Posts
    911
    Thanks
    302
    Thanked 2 Times in 2 Posts
    Hey,


    This works only for the first item in the table. Button # 8 in this case and Not for others


    The output would be something like







    Any idea why?
    Last edited by phantom007; 09-09-2008 at 07:58 AM.


  •  

    Posting Permissions

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