"Make updates to the data with the help of a button input

I am working on a form that has two input type buttons. The first button is labeled "edit", and when clicked, it enables the input field. The second button is labeled "save", and when clicked, it disables the input field and should save the new values in a MySQL database.

Everything is functioning correctly except for updating the value in the database after editing using the input type button. How can I achieve this without using submit to prevent page reload issues with enabling and disabling the input field?

Below is the jQuery code used to enable and disable the input fields:

<script>
     $(document).ready(function(){
         $("form input[type=text],form input[type=checkbox]").prop("disabled",true);
         $("input[name=edit]").on("click",function(){  $(this).closest("tr").find("input[type=text],input[type=checkbox],select").removeAttr("disabled");
         })
         $("input[name=save]").on("click",function(){   $(this).closest("tr").find("input[type=text],input[type=checkbox],select").prop("disabled",true);
     })
    </script>

/***********************************************/

<form name='' id='' action='' method='post'>
<input type='text' name='txt_category' id='category' value='$category' disabled>
<input type='text' name='txt_stage' id='stage' value='$stage' disabled>
<input type='checkbox' name='txt_approve' id='approve' value='$approve' disabled>
<input type='button' name='edit' value='edit'>
<input type='button' name='save' id='save' value='save'>
</form>

<?php
ob_start();
include("../includes/connect.php");
$id=$_POST['txt_id'];
$stage=$_POST['txt_stage'];
$category=$_POST['txt_category'];
$priority=$_POST['txt_priority'];
$frequency=$_POST['txt_frequency'];
$notapprove=$_POST['txt_notapprove'];
$approve=$_POST['txt_approve'];
$notexist=$_POST['txt_notexist'];
$wo=$_POST['txt_wo'];
$duration=$_POST['duration'];
$startdate=$_POST['startdate'];
$enddate=$_POST['enddate'];
$asd=$_POST['txt_asd'];
$add=$_POST['txt_add'];
$aduration=$_POST['txt_aduration'];
$transferredto=$_POST['txt_transferredto'];
$prb=$_POST['txt_percentage'];
$note=$_POST['txt_note'];
$projectname=$_POST['txt_projectname'];
if($notapprove==""){$notapprove="False";}else{$notapprove="True";}
if($approve==""){$approve="False";}else{$approve="True";}
if($notexist==""){$notexist="False";}else{$notexist="True";}
$sql=mysqli_query($conn,"update tbl_checklist set db_category='$category',db_stage='$stage',db_priority='$priority',db_frequency='$frequency',db_notapprove='$notapprove',db_wo='$wo',db_asd='$asd',db_add='$add',db_aduration='$aduration',db_transferredto='$transferredto',db_percentage='$prb',db_note='$note',db_approve='$approve',db_notexist='$notexist' where db_id='$id'")or die(mysqli_error($conn));
//header("location:checklist.php?msg=1&s=$projectname");
ob_end_flush();
?>

Answer №1

In order to make changes to your database, you will need to update it from the server side. If you wish to avoid page reloads, consider utilizing Ajax technology. For those using JQuery, there is a helpful guide on how to implement JQuery Ajax smoothly and effortlessly.

Answer №2

If you want to update data without reloading the page, you can utilize the following ajax method:

The data you are sending will be included either in the $_GET or $_POST global variables depending on the type of request being made. Below is a straightforward example:

$.ajax({                    
  url: 'content/get.php',     
  type: 'post', // making a POST request
  data : {
    data1 : 'value' // accessible in $_POST['data1']
  },
  dataType: 'json',                   
  success: function(data)         
  {
    // etc...
  } 
});

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Having trouble adding HTML content to a parent div using jQuery and BackboneJS?

Utilizing Backbone Marionette to create a series of views, I am now faced with the task of making an AJAX call to my backend. In order to provide visual feedback to the user indicating that an action is being performed, I decided to integrate a spinner int ...

Despite having unique ids, two file input forms are displayed in the same div in the image preview

Running into a minor issue once again. It may not be the most eloquent query, but I'm genuinely stuck and in need of some assistance. I am attempting to showcase image previews of selected files in a file input form. I have a jQuery script that reads ...

Using CakePHP to print data only when a condition is met with an array of specific IDs

I'm attempting to fetch and display the information from a particular query where the bstockBooksTableResearchIds matches the array(1,2,3), however, an error keeps appearing as shown below: $bstockBooksTableResearches = $this->BstockIn->Bstock ...

Utilizing an Application Programming Interface in React Native

Recently diving into React Native, I embarked on creating a basic app leveraging the Marvel API along with an API wrapper. My aim is to implement an infinite scroll view using VirtualizedList. Here's where I could use some guidance: What should be pas ...

Executing function after completion of ajax call

I have 2 buttons and 3 links that trigger an ajax request. I want to display an alert only when the request initiated by one of the buttons is completed, but not when a link is clicked. Below is my code: HTML: <button id="ajax1">Ajax 1</button&g ...

Sending form data without interrupting the user interface by using asynchronous submission

Using jQuery version 1.7.2, I am currently using the submit() method to send a form via POST. This triggers a Python cgi-bin script that performs some tasks which may take around ten seconds to finish. Upon completion of the task, the Python script instruc ...

Change the name of the state in Vue mapState

I have a specific situation in my computed where I need to track two different "loading" states. Is there a method to include an alias for the second state using this syntax? computed: { ...mapState('barcodes', ['barcodes', ' ...

Transforming a canvas element into an image sans the use of toDataURL or toBlob

Recently, I developed a small tool which involves adding a canvas element to the DOM. Strangely, when trying to use toBlob or toDataURL, I encountered an issue with the canvas being tainted and received the error message (specifically in chromium): Uncaugh ...

Error encountered while compiling NextJS: Unexpected use of single quotation mark in jsx-quotes

I can't seem to compile my NextJs 13 app without encountering errors. Take a look at my shortened eslintrc.js file below: module.exports = { env: { browser: true, es2021: true, }, extends: [ 'plugin:react/recommended', ...

Customer is unable to locate the "InitializeAuthenticationService" function

After launching my application, the browser console keeps showing me three errors that all say Could not find 'AuthenticationService.init' ('AuthenticationService' was undefined). and Microsoft.JSInterop.JSException: Could not find &apo ...

Creating a JSON object using various inputs through AngularJS

Just starting out with Ionic, Angular, and Firebase. This might be a silly question :) I'm working on an app using Ionic + Firebase, and I want to create a JSON object from multiple inputs. The interface looks like the image below: https://i.stack.i ...

Buttons within the Bootstrap carousel caption cannot be clicked

I am currently designing a webpage with a Bootstrap carousel that includes a paragraph caption and two buttons. However, the buttons are not functioning as clickable links - when clicked, nothing happens. {% block body %} <div id ="car-container"> ...

Excessive calls to the component update in React with Javascript are leading to application crashes

componentDidUpdate() { // Retrieving trades from the database and syncing with MobX store axios.get(`http://localhost:8091/trade`) .then(res => { this.props.store.arr = res.data; }) } After implementing this code, my ...

Determining the scroll position of a JQuery Mobile collapsible set upon expansion

I am utilizing jQueryMobile (v1.4.0) collapsible set / accordions to showcase a list of elements along with their content, which can be seen in this jsFiddle. <div id="List" data-role="collapsible-set"> <div data-role="collapsible" data-conte ...

Transferring token values between collections in POSTMAN - AUTOMATION | NEWMAN: A step-by-step guide

My goal is to streamline my unit test cases by utilizing the POSTMAN Collections API & NEWMAN. I successfully created two test cases that are performing as expected. Upon exporting the collection from POSTMAN, I proceed to generate the test report using NE ...

Navigating nested events with jQuery

Currently, I am dealing with a <span class="fold"></span> element that is controlled by the following jQuery code: $('.fold').click(function (event) { ... }); As new "fold" elements are added dynamically via ajax, I need to assign ...

Ways to troubleshoot and fix the problem of encountering an "Internal Server Error" when sending emails with nodeMailer in node.js

When attempting to send a confirmation email using nodemailer, I encountered an internet server error in production when allowing insecure apps for Gmail accounts, although it works fine locally. Any suggestions on how to resolve this issue? router.post(& ...

Retrieving data from varied React components - triggered by clicking a LOG button

function Copy() { const Message = "MESSAGE"; const [messageList, setMessageList] = useState([{ text: "Hello", id: 1 }]); const [newMessageValue, setNewMessageValue] = useState(0); const addToMessageList = () => { alert(n ...

How to Ensure Screen Opens in Landscape Mode with Phaser3

https://i.stack.imgur.com/keCil.pngIn my Phaser3 game, I am trying to achieve the functionality where the game opens horizontally in a webview without requiring the user to rotate their phone. The vertical photo below shows the game in its current state. W ...

Include a class in ul > li elements upon page load in Angular4

I attempted to add a class to each "li" element in an Angular4 page, but the class was not applied. Here is the relevant HTML code: <ul class="pagination"> <button class="previous" (click)="previous()">Previous</button> <button ...