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 4 of 4
  1. #1
    New Coder
    Join Date
    Jan 2007
    Posts
    42
    Thanks
    4
    Thanked 0 Times in 0 Posts

    if checkbox checked then do some php?

    hi
    i was wondering if there was anyway i can check a check box with the help of javascript and have it add text from a database record to a text box without submitting the page with the help from php? i have the php coding done to get the info and edit it but cant have no idea how to do the javascript code thanks.

    PHP code:
    PHP Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>Untitled Document</title>
    </head>
    <body>
    <div id="user_pm">
    <?php
    $sql
    ="SELECT * FROM list WHERE username='usernamehere'";
    $result=mysql_query($sql);
    $count=mysql_num_rows($result);
    ?>
    <table width="496" border="0" cellspacing="1" cellpadding="0">
    <tr>
    <td><form name="form1" method="post" action="">
    <table width="495" border="0" cellpadding="3" cellspacing="1" bgcolor="#000000">
    <tr>
    <td align="left" bgcolor="#3576B4" width="26"><font color="#FFFFFF" size="2"><strong></strong></td>
    <td align="left" bgcolor="#3576B4" width="95"><font color="#FFFFFF" size="2"><strong>From:</strong></font></td>
    <td align="left" bgcolor="#3576B4" width="52"><font color="#FFFFFF" size="2"><strong>To:</strong></font></td>
    <td align="left" bgcolor="#3576B4" width="161"><font color="#FFFFFF" size="2"><strong>Message:</strong></font></td>
    </tr>
    <?php
    while($rows=mysql_fetch_array($result)){
    ?>
    <tr>
    <td align="center" bgcolor="#f8f8f8" width="26">
    <input name="checkbox[]" type="checkbox" id="checkbox[]" value="<?php echo $rows['id']; ?>" style="float: left"></td>
    <td bgcolor="#f8f8f8" width="95"><font size="2"><?php echo $rows['from']; ?></font></td>
    <td bgcolor="#f8f8f8" width="52"><font size="2"><?php echo $rows['to']; ?></font></td>
    <td bgcolor="#f8f8f8" width="161"><font size="2"><?php echo $rows['message']; ?></font></td>
    </tr>
    <?php
    }
    ?>

    <tr>
    <td colspan="6" align="center" bgcolor="#f8f8f8">
    <input name="edit" type="submit" id="edit" value="Edit" style="float: left"></td>
    </tr>
    <?php
    $message 
    stripslashes($post['message']);
    $message $_POST['message'];
    $checkbox $_POST['checkbox'];
    $edit $_POST['edit'];
    if(
    $edit){
    for(
    $i=0;$i<$count;$i++){
    $edit_id $checkbox[$i];
    mysql_query("UPDATE list SET message='$message'  WHERE id='$edit_id' And username='usernamehere'");
    }
    if(
    $result){
    echo 
    "<meta http-equiv=\"refresh\" content=\"0;url=index.php\">\n";
    }
    }
    mysql_close();
    ?> 
    </table>
    </form>
    </td>
    </tr>
    </table>
    </div>
    </body>
    </html>

  • #2
    Regular Coder
    Join Date
    Apr 2012
    Location
    St. Louis, MO
    Posts
    985
    Thanks
    7
    Thanked 101 Times in 101 Posts
    You can use AJaX to access a php file that will retrieve the data from the database and update just about anything without refreshing the page.
    ^_^

    If anyone knows of a website that can offer ColdFusion help that isn't controlled by neurotic, pedantic jerks* (stackoverflow.com), please PM me with a link.
    *
    The neurotic, pedantic jerks are not the owners; just the people who are in control of the "popularity contest".

  • #3
    New Coder
    Join Date
    Jun 2012
    Posts
    43
    Thanks
    15
    Thanked 0 Times in 0 Posts
    How can we use Ajax to update a php file? isnt ajax client side?

  • #4
    Senior Coder
    Join Date
    Dec 2010
    Posts
    2,391
    Thanks
    11
    Thanked 568 Times in 561 Posts
    The OP did not ask to update a php file. He/She asked to execute a PHP file after changing a checkbox and then write the output of the PHP into a textbox.

    And this is the domain of Ajax.


  •  

    Posting Permissions

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