I am trying to post values from textarea fields, via Ajax, so the page doesn't need to turn over.
Code: Select all
<script type="text/javascript" src="/js/js_ajax_updateproductmetas.js"></script>
<div id='formmeta$row->id'>
<form>
<input type='hidden' id='id' name='id' value='$row->id'>
Title Tag:<br/>
<input type='text' id='titletag' name='titletag' value='$row->titletag' style='width: 450px'><br/><br/>
Meta Keywords:<br/><textarea name='metakeywords' id='metakeywords' style='font-family: arial; font-size: 11.2px; width:450px' rows='5'>$row->metakeywords</textarea><br/><br/>
Meta Description:<br/><textarea name='metadescription' id='metadescription' style='font-family: arial; font-size: 11.2px; width:450px' rows='5'>$row->metadescription</textarea><br/><br/>
<input type='button' value='Submit' id='submit' class='updateproductmetas'></form>
</div>
Code: Select all
$(document).ready(function() {
$(".updateproductmetas").click(function() {
var formmeta = $(this).parent('form');
var id = formmeta.children('input[name=id]').val();
var titletag = formmeta.children("input[name=titletag]").val();
var metadescription = formmeta.children("input[name=metadescription]").val();
var metakeywords = formmeta.children("input[name=metakeywords]").val();
// etc
// Returns successful data submission message when the entered information is stored in database.
var dataString = '&id=' + id + '&titletag=' + titletag + '&metadescription=' + metadescription + '&metakeywords=' + metakeywords;
if (id == '') {
alert("Please Fill All Fields");
} else {
//AJAX code to submit form.
$.ajax({
type: "POST",
url: "ajax_updateproductmetas.php",
data: dataString,
cache: false,
success: function(result) {
alert(result);
}
});
}
return false;
});
});Code: Select all
<?php
session_start();
$id = isset($_POST['id']) ? $_POST['id'] : null;
$titletag = isset($_POST['titletag']) ? $_POST['titletag'] : null;
$metadescription = isset($_POST['metadescription']) ? $_POST['metadescription'] : null;
$metakeywords = isset($_POST['metakeywords']) ? $_POST['metakeywords'] : null;
if (isset($_SESSION["loggedin"])) {
$usertype = $_SESSION["usertype"];
if ($usertype == "admin")
{
include "dbconn.php";
mysql_query("UPDATE products SET titletag = '$titletag', metadescription = '$metadescription', metakeywords = '$metakeywords' WHERE id = '$id'");
}}
?>I'm convinced it's how I am handing the Parent, the Form and the outer Div. But cannot put my finger on it.
Help!!