How To Save And Close A Bootstrap Modal? January 21, 2024 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 Displaying Multiple Series In The Navigator Of An HighStock Chart I would like to create an HighStock chart containing a navi… Edit A Txt File Using Javascript/jquery I want to modify a .txt (overwrite completely) using javasc… Determine The 'Overtype' Mode Using Javascript We are creating a web app to replace an old-school green-sc… Prevent Right/left Arrow Navigation In Select I have 3 selects that I am enabling keyboard navigation(rig… Regular Expression To Force Single Blank Space After A First Character How do I force a space after first character as user types.… How To Add Pagination In Table Using D3? i have following code,i have to add pagination on this tabl… Node Js Auto Restart All Forever Js Process When Server Goes Down / Crashes I am using forever js to keep my node server running 24/7 o… SweetAlert - Change Modal Width? I love this library. I'd like to use it to display a m… Specific Number Of Elements In Loop Are Not Selecting If Data Retrieving From Json Or Xmlhttprequest In Javascript Looking for selection of next few elements by onclick on &#… What Is The Difference Between () => {} And Function() {} In React-native Javascript? I have seen some functions defined as function(){} and some… December 2024 (1) November 2024 (37) October 2024 (67) September 2024 (23) August 2024 (375) July 2024 (342) June 2024 (729) May 2024 (1297) April 2024 (822) March 2024 (1564) February 2024 (1737) January 2024 (1402) December 2023 (1432) November 2023 (433) October 2023 (601) September 2023 (306) August 2023 (350) July 2023 (271) June 2023 (387) May 2023 (221) April 2023 (125) March 2023 (141) February 2023 (185) January 2023 (261) December 2022 (133) November 2022 (216) October 2022 (168) September 2022 (163) August 2022 (509) July 2022 (291) June 2022 (320) Menu Halaman Statis Beranda © 2022 - JavaScript Free