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 9049537
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T12:25:27+00:00 2026-06-16T12:25:27+00:00

Below I have an jquery with ajax code where it will display change the

  • 0

Below I have an jquery with ajax code where it will display change the values of course details by inserting the new data from one set of inputs (the set of inputs where the user has made changes) to another set of inputs (the set of inputs where it states the course’s current details). Also the course’s drop down menu changes to accommodate the new change if it needs to change:

 function submitform() {    

    $.ajax({
        type: "POST",
        url: "updatecourse.php",
        data: $('#updateCourseForm').serialize(),
        success: function(html){
            $("#targetdiv").html(html);
            //Get and store the new course number and name.
                var newCourseNo = jQuery("#newCourseNo").val();
                var newCourseName = jQuery("#newCourseName").val();
                var newDuration = jQuery("#newDuration").val();

                //Set your current course number and name to your number and name.
                jQuery("#currentCourseNo").val(newCourseNo);
                jQuery("#currentCourseName").val(newCourseName);
                jQuery("#currentDuration").val(newDuration);

                //Find the currently selected course and update it.
                var selectedOption = jQuery("#coursesDrop option:selected");
                var label = selectedOption.text().split(" - ");
                selectedOption.text(newCourseNo + " - " + newCourseName);

                $('#targetdiv').show();
        }
     });        
}

Now $("#targetdiv") is the id where it displays the success or error message retrieved from the php page which is accessed through ajax:

updatecourse.php:

...//mysqli code

echo "<span style='color: green'>Course details have been updated:<br/>" . $newcourseno . " - " . $newcoursename . "</span>";

}else{

echo "<span style='color: red'>An error has occured, Course Details have not been updated</span>";

}

But the problem I am having is that if the error message from the php code is retrieved in the jquery, then I don’t want the course details to make the edit in jquery to accomodate the current course text inputs to insert the new details. I only want that to happen if the success message appears.

If the error message appears I want no change to happen, the current course details inputs and the new course details input simply remain the same before the submit.

But how can this be achieved?

  • 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-16T12:25:28+00:00Added an answer on June 16, 2026 at 12:25 pm

    Get response as JSON (so that you can manipulate the response after you get result…)

    try this,

    JQUERY

    $.ajax({
        type: "POST",
        url: "updatecourse.php",
        data: $('#updateCourseForm').serialize(),
        dataType:'json';  //get response as json
        success: function(result){
            if(result.errorflag){
    
               //do your stuff on getting error message
              var newHtml="<span style='color: red'>"+result.msg+"</span>" 
              $("#targetdiv").html(newHtml);  //i am displaying the error msg here
    
            }else{
               //you got success message
    
               var newHtml="<span style='color: green'>"+result.msg+"</span>" 
               $("#targetdiv").html(newHtml);
               //Get and store the new course number and name.
                var newCourseNo = jQuery("#newCourseNo").val();
                var newCourseName = jQuery("#newCourseName").val();
                var newDuration = jQuery("#newDuration").val();
    
                //Set your current course number and name to your number and name.
                jQuery("#currentCourseNo").val(newCourseNo);
                jQuery("#currentCourseName").val(newCourseName);
                jQuery("#currentDuration").val(newDuration);
    
                //Find the currently selected course and update it.
                var selectedOption = jQuery("#coursesDrop option:selected");
                var label = selectedOption.text().split(" - ");
                selectedOption.text(newCourseNo + " - " + newCourseName);
    
                $('#targetdiv').show();
             }
          }
     }); 
    

    PHP

    json_encode() to send the reponse as json…. send response as array with the error flag to check if it is a succcess or error and the msg to print…

    ...//mysqli code
    
        echo json_encode(array('errorflag'=>false,'msg'=>"Course details have been updated:<br/>" . $newcourseno . " - " . $newcoursename));
    
      }else{
    
      echo json_encode(array('errorflag'=>true,'msg'=>"An error has occured, Course Details have not been updated"));
    
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have written some code using jQuery to use Ajax to get data from
I am trying to fetch wcf service from jquery. I have written below code
I have php/mysqli and jquery code below where it displays a course drop down
How can i implement the below code with jQuery/AJAX timer,(I have created 2 URL
The below code is very simple. I have a jQuery autocomplete bound to an
I have this javascript code below that uses jquery, it is suppoed to be
I have a jquery code below which is displayed in the editsessionadmin.php page. Now
Below I have a piece of code where it is suppose to display 2
Few questions: I'm using CI and JQuery AJAX. In my code below, I assemble
Basically, the code below will generate divs which are then captured using the jquery

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.