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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.