Jump to content

Submit Form & Write to DB using AJAX


chronister

Recommended Posts

Hi All,

 

I am completely ignorant of AJAX and Javascript in general. I can write PHP fairly decent, I just have not had the time to sit down and try to learn javascript.

 

I would like to create a "post-it" note for my wife's intranet site. I have a text area that I have masked with some CSS so it don't look like a text area.

 

I want to be able to simply type into the box and then through either an onChange or onBlur event trigger the AJAX request and write the updated notes to the database. I would like to make it happen without a submit button being pressed.

 

I have checked out some ajax scripts and I just don't understand them enough to mess with them. Can someone point me in the right direction?

 

The form I want to submit is below.

 

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
<style type="text/css">
<!--
#textarea {
border-top-width: 1px;
border-right-width: 1px;
border-bottom-width: 1px;
border-left-width: 1px;
border-top-style: dashed;
border-right-style: dashed;
border-bottom-style: dashed;
border-left-style: dashed;
background-color: #FFFFFF;
}
-->
</style>
</head>
<body>
<form id="post-it" name="post-it" method="post" action="">
  <textarea name="notes" cols="50" rows="5" wrap="virtual" id="textarea" onChange="<!--call ajax-->" ></textarea>
  
</form>
</body>
</html>

 

The php I want run is basically this.

 

<?php

$notes=$_POST['notes'];
connectdb();
$query="UPDATE notes SET notes='$notes' ";
$result=mysql_query($query);
if(mysql_affected_rows($result) > 0){
	$message="Updated Notes Sucessfully";
}
?>

 

I appreciate any input you folks can give me on this.

 

Nate

Link to comment
https://forums.phpfreaks.com/topic/43561-submit-form-write-to-db-using-ajax/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.