The submission of jQuery UI modal dialog is ineffective

My Objective: I want the user to input a client's name in an autocomplete field and select the desired client. Once selected, the Apply button should become enabled.

Upon clicking the Apply button, the ClientName and ClientId should be submitted to a different PHP page.

Current Challenge: Although everything is functioning correctly, the redirection or posting to the specified page URL in the form action is not occurring as expected.

If anyone could provide assistance, it would be greatly appreciated.


$(function() {
 $("#btnCancelId").button();
     $("#btnApplyId").button();
     $('#btnApplyId').attr('disabled', true);
 $("#btnAddId").button();
     $('#btnAddId').click(function() {$divDialog.dialog('open'); return false;});

     $('#txtClientName').bind('keyup', function() {
 $('#txtClientId').val('');
 $('#txtClientId').css({'background-color': '#FFC0C0'});
 $("#btnApplyId:eq(0)").addClass("ui-state-disabled").attr("disabled", true);
  });

    var $divDialog = $('#divDialog');
    $divDialog.dialog({
  autoOpen: false,
  modal: true,
  title: 'Company name',
  buttons: [{
     id: 'btnCancelId',
     text: 'Cancel',
     click: function() {$divDialog.dialog('close');}
     },{
      id: 'btnApplyId',
      text: 'Apply',
      disabled: true,
      click: function() {
        $('#client_form').submit();
    //    $divDialog.dialog('close');
     }
     }]
 });

    $("#txtClientName").autocomplete({
      source: "_ajcustlist.php",
      minLength: 2,
      select: function(event, ui) {
   $("#btnApplyId:eq(0)").removeClass("ui-state-disabled").attr("disabled", false);
            $('#txtClientId').val(ui.item.id);}
    });
});

The HTML code:

<div id="divDialog">
  <form id="client_form" name="client_form" method="post" action="editinv.php">
   <input type="text" id="txtClientName" name="txtClientName" />
   <input type='text' id='txtClientId' name='txtClientId' style='display:none'/>
  </form>
</div>

Answer №1

Your dialog action button's click event needs to be corrected. Currently, it is attempting to submit a div ($('#divDialog')) instead of the form ($('#client_form')) located within the div.

Update the code as follows:

click: function() {
    $('#client_form').submit();
    //    $divDialog.dialog('close');
}}]

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

Utilizing jQuery and DOM to interact with form elements

Below is the form content <form method="post"> <input type="hidden" name="resulttype" value="Create"> <table> <tr> <td>Full Name</td> <td><input ...

Is there a way to confirm if the target has been successfully removed from the element using jQuery?

$(".dropdown-toggle").click(function(event) { var target = $(event.target); if (target.is(this)) { $(this).find(".caret").toggleClass("customcaret"); } }); <div class="dropdown-toggle"> <div class="caret"></div> </div> ...

Convert an AJAX JSON object into values for multiple text boxes

When making an ajax call, I receive the following JSON input: var json = { "id_u":"1", "nombre_usuario":"JESUS", "apellido_paterno_usuario":"DIAZ", } I have text inputs that correspond to each key in the JSON object: <input type="text" name="id ...

Unable to resolve an unresolved issue with a jquery or javascript bug

I am currently facing some issues with my jQuery code in both Firebug and Chrome's developer tools. Any assistance would be greatly appreciated. Kindly make the necessary updates in the provided fiddle. Please follow this link to access the fiddle: ...

Curious about making an AJAX call with jQuery?

As I work on a jQuery ajax statement, my main goal is to receive a payload from the server and then process it in a separate function. However, I'm currently facing some difficulties with the syntax of the function. $.ajax({ url: 'mypgm ...

Incorporate HTML code dynamically within a div using jQuery

I need assistance with this code: jQuery('.post-single-content').addClass('padT'); jQuery('.post-single-content').css("padding-top", "40px"); This piece of code essentially changes the following: <div class= ...

A step-by-step guide on leveraging ajax for submitting comments in WordPress

I am currently working on developing a custom WordPress theme that includes a unique contact form. This contact form is designed to store data in a custom post type called "Messages" whenever a user submits the form. Below is the code snippet for the cont ...

Trigger a function in jQuery when the DOM undergoes changes

Up until now, I have been utilizing livequery which has served its purpose. However, it tends to slow down the page browsing experience, so I am in search of an alternative solution. I have a function that performs ajax on elements with a specific class l ...

Encountering repetitive actions during the processing of the MVC controller operation

Currently, I'm making an ajax request to my controller for processing. However, when I look at the message in my ajax done function, it displays two outcomes. The output from console.log is: {"result_code":1,"result_message":"Contact tags deleted"," ...

How can we convert a group of HTML elements sharing a common attribute into an array containing their respective values?

Consider the following HTML structure: <span class="L5" letters="a"></span> <span class="L5" letters="b"></span> <span class="L5" letters="c"></span> <span class="L5" letters="d"></span> <span class="L5" ...

Issue with JQuery DatePicker on IE11: Object does not support the swap property or method

My webpage includes the html5 tag: <input type="date" name="date" id="date"> While this tag functions properly on smartphones and in Microsoft Edge browser, it does not work on Internet Explorer. To ensure compatibility with IE11, I made the follow ...

Issue with HighCharts: Bar columns not extending to the x-Axis when drilling up

I am encountering an issue with HighChart/HighStock that I need help with. To illustrate my problem, I have set up a JSFiddle. The problem arises when a user drills down on a bar column, causing the y-axis to shrink and consequently making the x-axis appea ...

Utilizing Jquery within Reactjs

Currently, I am encountering an issue while attempting to implement Materialize CSS in React JS. Some of the CSS components require jQuery for initialization or animation. Is it advisable to use jQuery in React JS? And if so, how can I incorporate jQuery ...

Choose an element that has either one attribute or another attribute

Is there a way to select all elements containing specific attributes from a given list? For instance, I am looking to target elements that possess either the mandatory attribute, or the validate='true' attribute, or even both. I attempted the fo ...

What is the best way to limit the top margin for a fixed element?

Recently, I came across this code snippet: jQuery(document).ready(function($){ $( window ).scroll(function() { var current_top = $(document).scrollTop(); var heights = window.innerHeight; document.getElementById("sHome").styl ...

The <a href="#divtagid"> link is incapable of triggering the opening of the div tag when called from JavaScript

I need help with displaying the content of a div with the id "hello" in maindiv when clicking on the href "Click Here", but it's not working as expected. Here is the code I have: $(document).ready(function() { var newhtml = '<a href="#he ...

I am having trouble passing a variable into the AJAX URL using JavaScript

Currently, I am attempting to remove an item from mongodb. However, I am encountering difficulty passing the id into the URL through the ajax call. Below is my code: $(".delete-item").on('click', function(e, id) { var deleteName = ...

Shake up your background with a random twist

Seeking assistance with customizing the Aerial template from HTML5UP. I am interested in selecting a scrolling background randomly from a pool of images. Can someone guide me on how to achieve this? Presently, the background is defined within a code block ...

The JSON array object gets replaced in the local storage

I have been working on a form page where there are 3 input fields: "fname," "emailId," "phoneNo." Every time a user enters details in the form, I am storing them in localStorage. However, the object keeps getting overwritten. Here is the script: <scri ...

Include chosen select option in Jquery form submission

Facing some challenges with a section of my code. Essentially, new elements are dynamically added to the page using .html() and ajax response. You can see an example of the added elements in the code. Since the elements were inserted into the page using . ...