Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9233977
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T06:40:51+00:00 2026-06-18T06:40:51+00:00

I am currently trying to update a textarea when a user clicks elsewhere. I’m

  • 0

I am currently trying to update a textarea when a user clicks elsewhere. I’m not well-versed in AJAX and Jquery. However, the script doesn’t seem to be updating the row in the DB.

Jquery/Text area:

<textarea id="<?php echo $item_id; ?>_textarea"><?php echo $notes; ?></textarea>
    <script type="text/javascript">
    $('<?php echo $item_id; ?>_textarea').on('blur',function () {
var notesVal = $(this).val(), id = $(this).data('id');        
var itemVal = <?php echo $item_id; ?>;
$.ajax({
     type: "POST",
     url: "updateNotes.php",
     data: {notes:notesVal , id:id, itemId:itemVal},
     success: function(msg) {
         $('#'+id).html(msg);
     }
 })
});
</script>

updateNotes.php:

<?php

include('db_connect.php');
include('order_functions.php');



$email = $_SESSION['username'];

$cartId = getcartid($mysqli, $email);
$notes = $_POST['notes'];
$itemID = $_POST['itemId'];


$query = "UPDATE `rel` SET `notes` = '$notes' WHERE `cart_id` = '$cartId' && `id_item` = '$itemID'";
$result = $mysqli->query($query) or die($mysqli->error.__LINE__);

if(result) {
return "Notes Updated";

}
?>

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T06:40:52+00:00Added an answer on June 18, 2026 at 6:40 am

    You forgot the $ in your last if-statement in your php-code and you should use “echo” (or likewise) instead of “return” as you are not in a function.

    <?php
    
    include('db_connect.php');
    include('order_functions.php');
    
    $email = $_SESSION['username'];
    
    $cartId = getcartid($mysqli, $email);
    $notes = $_POST['notes'];
    $itemID = $_POST['itemId'];
    
    
    $query = "UPDATE `rel` SET `notes` = '$notes' WHERE `cart_id` = '$cartId' && `id_item` = '$itemID'";
    $result = $mysqli->query($query) or die($mysqli->error.__LINE__);
    
    if($result) {
        echo "Notes Updated";
    }
    ?>
    

    Your html/javascript-code is a bit wrong. This is how i guess you wanted it to work:

    <div id="<?php echo $item_id; ?>_div">
        <textarea id="<?php echo $item_id; ?>_textarea" data-id="<?php echo $item_id; ?>"><?php echo htmlentities($notes); ?></textarea>
    </div>
    
    $('#<?php echo $item_id; ?>_textarea').on('blur', function () { // don't forget # to select by id
    
        var id = $(this).data('id'); // Get the id-data-attribute
        var val = $(this).val();
        $.ajax({
            type: "POST",
            url: "updateNotes.php",
            data: {
                notes: val, // value of the textarea we are hooking the blur-event to
                itemId: id // Id of the item stored on the data-id
            },
            success: function (msg) {
                $('#' + id + '_div').html(msg); //Changes the textarea to the text sent by the server
            }
        });
    });
    

    Good luck

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm currently trying to write a script that will change a user's role to
Currently trying at add ajax to a site, after much reading I discovered that
I'm currently trying to update my in house search engine to use multiple words.
I'm currently trying to created a custom ConfigurationSection for my application, however VS2008 is
I'm currently trying to make a page via php which allows the user to
I'm currently trying to load a sql script to create a HSQL database. This
im currently trying to update my project to 64bit support. The project used to
I am currently trying to update a chart which is on my form to
I am currently trying to figure out how to update documents in MongoDb via
We are currently trying to implement a SELECT FOR UPDATE in order to lock

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.