Go Back   CodingForums.com > :: Client side development > JavaScript programming > Ajax and Design

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 05-18-2012, 03:34 PM   PM User | #1
ycpc55
New Coder

 
Join Date: Jan 2007
Posts: 42
Thanks: 4
Thanked 0 Times in 0 Posts
ycpc55 is an unknown quantity at this point
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>
ycpc55 is offline   Reply With Quote
Old 05-19-2012, 08:17 AM   PM User | #2
WolfShade
Regular Coder

 
Join Date: Apr 2012
Location: St. Louis, MO, USA
Posts: 952
Thanks: 7
Thanked 98 Times in 98 Posts
WolfShade is an unknown quantity at this point
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".
WolfShade is offline   Reply With Quote
Old 06-05-2012, 01:56 PM   PM User | #3
codingrox
New Coder

 
Join Date: Jun 2012
Posts: 31
Thanks: 12
Thanked 0 Times in 0 Posts
codingrox is an unknown quantity at this point
How can we use Ajax to update a php file? isnt ajax client side?
codingrox is offline   Reply With Quote
Old 06-06-2012, 09:40 AM   PM User | #4
devnull69
Senior Coder

 
Join Date: Dec 2010
Posts: 2,245
Thanks: 10
Thanked 531 Times in 525 Posts
devnull69 will become famous soon enough
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.
devnull69 is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 07:34 AM.


Advertisement
Log in to turn off these ads.