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

  • Home
  • SEARCH
  • 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 406051
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T17:27:31+00:00 2026-05-12T17:27:31+00:00

I have a view_mine_and_others.php file that outputs this html <div class=rec id=1> <div class=val>343</div>

  • 0

I have a view_mine_and_others.php file that outputs this html

<div class="rec" id="1">
 <div class="val">343</div>
 <a class="change">Change</a>
</div>
<div class="rec" id="2">
 <div class="val">12001</div>
 <a class="change">Change</a>
</div>
<div class="rec" id="3">
 <div class="val">4233</div>
 <a class="change">Change</a>
</div>

I have the links (<a class="change">) bound to a js function function change() that reads the id and val of the record involved, with the attention to send this data off to an update.php script.

$("a.change").click(change);

function change(){
   var id = $(this).parent().attr('id'); 
   var val = $(this).siblings('.val').html();

   /* this I'm guessing is where I call the ajax code */

   /* I then have some code here to udpate the interface if successful *
}

update.php will check if the user is authorized to make this change and will make the change if so. It will also set $success = 0 or 1 depending as a success indicator. This $success isn’t returned in any way since it’s not a function, it’s just an internal variable that I have in the update script that could be used if needed.

  • How do I make the ajax call such that I get feedback whether the update was allowed ($success=1 in update.php) or not (success = 0 in update.php). I’ll use that feedback to update the interface differently.

Extra info:

  • Note that I opted not to use a form 🙂 just doing with the <a>

  • The update.php script is expecting a $_POST['id'] and $_POST[val] (I’m not going to post the code for update.php here since it’s not the point, I’m sure you can imagine what it looks like and what it does)

  • 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-05-12T17:27:31+00:00Added an answer on May 12, 2026 at 5:27 pm

    Here’s the quick rundown since the above solutions seemed to miss a few steps and this code handles sanitizing your $_POST data and is perhaps slightly easier to follow:

    JAVASCRIPT:

    function change() {
       var id = $(this).parent().attr('id'); 
       var val = $(this).siblings('.val').html();
    
       $.post('/view_mine_and_others.php', { id: id, val: val }, function(data) {
          if (data == '1') {
             alert('success');
          } else {
             alert('error');
          }
       });
       // you MUST return false or the A button will still fire the click event
       return false;
    }
    

    PHP:

    // assumes both id and val are integer values (sanitizes data)
    $id   = (isset($_POST["id"])) ? (int) $_POST['id'] : null;
    $val  = (isset($_POST['val'])) ? (int) $_POST['val'] : null;
    
    // do your database work here
    // and assume that you create a variable
    // called $success which is either true or false
    // depending on if the update was successful
    
    // echo the response to be picked up by the AJAX request
    echo ($success) ? 1 : 0;
    die;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 235k
  • Answers 235k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer The main difference between a reference and a tracking reference… May 13, 2026 at 6:14 am
  • Editorial Team
    Editorial Team added an answer Try: UPDATE announcements a SET announcer = (SELECT memberid FROM… May 13, 2026 at 6:14 am
  • Editorial Team
    Editorial Team added an answer As long as the data is passed to the view… May 13, 2026 at 6:14 am

Related Questions

I have a web application that you can use to import information from another
I have a very simple question about transactions. (In sql server 2000, but I
Ok...... I'm implementing a simple OpenGL ES application on the iPhone and I recently
I'm stumped. A client and I are both running Firefox 3.0.12 on XP machines.

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.