How To Save And Close A Bootstrap Modal? December 11, 2023 Post a Comment This question have many answers out there but none of those answers solved my problem. I have a modal with some tags. I am trying to save the values from the selecSolution 1: HTML<div id="someModalId"class="modal fade" role="dialog"> <divclass="modal-dialog"><!-- Modal content--><divclass="modal-content"><divclass="modal-header"><buttontype="button"class="close"data-dismiss="modal">×</button><h4class="modal-title">Modal Header</h4></div><divclass="modal-body"><selectid="exampleSelect"></select></div><divclass="modal-footer"><buttontype="button"class="btn btn-default"data-dismiss="modal">Close</button><buttonid="save"onclick="save()"class="btn btn-width bkgrnd-cyan save-details"type="button"name="save-details">Save</button></div></div>CopyJS$('#save').click(function() { $select_value = $("#exampleSelect").value(); $('#someModalId').modal('hide'); }); CopyGive your select a name or idSet the value of select to a global variable. Make sure to declare the variable at the top if you are getting an error. Solution 2: I'm not sure the id=1 is fine, but you can use this code to simulate a click on the close button (or you can add an id or a class to it).You may have to remove the onclick="save()"data = {}; $("#save").on("click", function(e){ e.preventDefault(); // prevent de default action, which is to submit// save your value where you want data.select = $("#exampleSelect").value(); // or call the save function here// save(); $(this).prev().click(); }); CopySolution 3: <button id="save" class="btn btn-width bkgrnd-cyan save-details"type="button" name="save-details" onclick="save()" data-toggle="modal" data-target="#myModalList" data-dismiss="modal">Save</button> Copythis worked very well for me, and its a simple way to do it. after the onclick I used the data-toggle, data-target and data-dismissin the js function save() I didn't need to code anything but to save data into to my database // Insere notas na base de dadosfunctionsave() { console.log("func guardar"); if ($("#message-text").val() == "") { alert("Texto vazio"); } else { $(document).ready(function () { $.ajax({ method: "POST", url: "../portal/portalphp/notas.php", data: { num: num, text: $("#message-text").val() } }).done(function (msg) { if (msg == 1) { //alert("Nota guardada com sucesso");readyNotas(num); console.log("func guardar done == 1"); } else { alert("Erro: não foi possivel guardar"); } }); texto.value = ""; }); console.log("func guardar ready"); } } CopySolution 4: First, you need to remove onclick="save()" from your button. You don't need that when you are using the on click function directly $('#save').click(function()...As was pointed out in the comments by @Eshwaren, you can't use a number to start an id, so you need fix that as well.To get the value from a select, you have to be able to identify it. A simple solution would be to give your select element an ID.For example:<divclass="modal-body"><selectid="data_1"></select></div>CopyIn your code, you can then assign the value of the select element to a variable.For example:var data_1; $('#save').click(function() { data_1 = $("#data_1").value(); $('#modalid').modal('hide'); }); CopyYou can then use that variable elsewhere in your code.There are many more possibilities for solving this, but the root of the issue is being able to identify the select elements in code and recording their respective values.Solution 5: thats my modal window$(function () { $("#dialog").dialog({ modal: true, autoOpen: false, title: "Column Preferences", button: "save", width: 750, height: 620 }); Copytry this to close or hide the window$('#dialog').dialog('close'); Copy Share Post a Comment for "How To Save And Close A Bootstrap Modal?" Top Question JQuery: If A Table Header Has A Class, Add Class To Table Cell Let's say I have the following html: … WebRTC Video Constraints Not Working I'm trying to get a lower resolution from the webcam na… HasClass Doesn't Work In My Js Code? I want to use hasClass in the following code, but that does… Capturing .click For URLs I am relatively new to Javascript/Ajax. When the user click… Highcharts Donutchart: Avoid Showing Duplicate Legend With Nested Charts I am trying to represent nested data using Highcharts Donut… How Do I Use Data From Vue.js Child Component Within Parent Component? I have a form component where I use a child component. I wa… Logic For The Next Button For The Questionnaire? I am beginner in AngularJS and facing some issues. I am try… Assignment To Property Of Function Parameter (no-param-reassign) I have this function and while I have this working nicely, … Payload Error In Jsonwebtoken I am making a web application using nodejs and angular cli … How To Show Website Preloader Only Once I added a preloader to my website and the preloader animati… December 2024 (1) November 2024 (36) October 2024 (71) September 2024 (24) August 2024 (366) July 2024 (341) June 2024 (707) May 2024 (1298) April 2024 (798) March 2024 (1514) February 2024 (1659) January 2024 (1321) December 2023 (1338) November 2023 (386) October 2023 (580) September 2023 (268) August 2023 (327) July 2023 (258) June 2023 (361) May 2023 (223) April 2023 (123) March 2023 (145) February 2023 (183) January 2023 (272) December 2022 (128) November 2022 (234) October 2022 (168) September 2022 (166) August 2022 (495) July 2022 (290) June 2022 (289) Menu Halaman Statis Beranda © 2022 - JavaScript Creator