SitePoint Sponsor

User Tag List

Results 1 to 7 of 7
  1. #1
    SitePoint Enthusiast
    Join Date
    Nov 2010
    Posts
    32
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    how to post the value of checkbox in ajax call

    i retrieved data from mysql table into html page i.e
    Code:
    $query="select * from student";
    $result=mysql_query($query)or die(mysql_error());
    while($rs=mysql_fetch_array($result))
    {
    ?>
    <tr>
          <td align="center"><?php echo $rs['st_id']; ?></td>
    <td align="center"><?php echo $rs['name']"; ?></td>
    <td align="center">&lt;input type="checkbox" name="check" <?php if($rs['checked']==1){echo "checked"; } ?> /></td>
    <td align="center"><a href="delete_student.php?id=<?php echo $rs['st_id'];?>"><img src="images/delete_icon.png" alt="Delete" /></a></td>
    <td align="center"><a href="update_student.php?id=<?php echo $rs['st_id'];?>"><img src="images/update.png" alt="Update" /></a></td>
    </tr>
    this is gives me the output
    [/url]

    assume that checkbox of id 1 is checked and retrieved from mysql table.
    <br /> Now what i want to do is that when i checked the remaing two checkbox into this table and a function is called to ajax which goes to php page and update the value of checked field according to the given id (i.e 2 and 3 in this case). Not refreshing the whole page nor updating the whole record just the value of check box.<br/> i am new to ajax so
    any help would be greatly appreciated.

  2. #2
    From Italy with love silver trophybronze trophy
    guido2004's Avatar
    Join Date
    Sep 2004
    Posts
    9,494
    Mentioned
    161 Post(s)
    Tagged
    4 Thread(s)
    Do you need help with the PHP script that'll update the MySQL table?
    Or with the javascipt part that has to call the PHP script, send it the relevant data and receive the response?

  3. #3
    SitePoint Enthusiast
    Join Date
    Nov 2010
    Posts
    32
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    i need help in javascript part cause i am new to ajax, i don't know how to call ajax when i click on specific checkbox with relevant st_id and then how ajax call the php script.

  4. #4
    From Italy with love silver trophybronze trophy
    guido2004's Avatar
    Join Date
    Sep 2004
    Posts
    9,494
    Mentioned
    161 Post(s)
    Tagged
    4 Thread(s)
    Ok, I'll ask for this post to be moved to the javascript forum, that way you'll have more possibility to get a quick and good answer.

  5. #5
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,682
    Mentioned
    99 Post(s)
    Tagged
    4 Thread(s)
    Quote Originally Posted by semanticnotion View Post
    i need help in javascript part cause i am new to ajax, i don't know how to call ajax when i click on specific checkbox with relevant st_id and then how ajax call the php script.
    The technique you are wanting to use is where the onchange event of the checkbox is used to both perform the ajax request to the database, and to replace the update button with an animated updating icon until a successful response from the server is received.

    Does your web page already use any javascript library, such as jQuery, so that you can leverage off of that pre-existing library to make your life a lot simpler?
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript

  6. #6
    SitePoint Enthusiast
    Join Date
    Nov 2010
    Posts
    32
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    No there is no jQuery library in my page there should be onclick or onchange event on my checkbox.

  7. #7
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,682
    Mentioned
    99 Post(s)
    Tagged
    4 Thread(s)
    Quote Originally Posted by semanticnotion View Post
    No there is no jQuery library in my page there should be onclick or onchange event on my checkbox.
    We'll use the onclick event so that the event occurs as soon as you click on it.

    I have to go now, but if you want some guidance on how it's done, there is a very good resource on performing ajax updates, in the book Bulletproof Ajax which also freely provides the code examples and working demos.
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript


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
  •