How To Save And Close A Bootstrap Modal? December 18, 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 Can One Use The Fetch API As A Request Interceptor? I'm trying to run some simple JS functions after every … Hide Submit Button Using Javascript How do I hide the submit button using javascript? Reason is… Why Do Browsers Allow Onmousedown Js To Change Href? I've noticed for a very long time that when you try to … C++, Win32 Api: How To Create An Html Rendering Window So That Your Application Would Get Callbacks From JS Calls? What I need is simple: we have a console app project. We wa… Menuitem And Contextmenu Crossbrowser Compatibility Problem 1: I had made my own contextmenu using the followin… Get Seleceted Dropdown Option Value Jquery I have two dropdowns -- for the month and year -- and a but… How To Escape Special Characters In Regular Expressions For my website I use the dataTable plugin and to give the u… How Can I Attach Event To A Tag Which Is In String Form? I'm creating html on runtime like this: var myVar = … AngularJS Image Upload Using Php I've got a problem with an image upload in AngularJS. I… Node.js Url Without Port Number I'm creating node.js project now. I've a VPS which … November 2024 (37) October 2024 (49) September 2024 (22) August 2024 (205) July 2024 (180) June 2024 (398) May 2024 (667) April 2024 (429) March 2024 (784) February 2024 (901) January 2024 (740) December 2023 (771) November 2023 (311) October 2023 (531) September 2023 (283) August 2023 (322) July 2023 (277) June 2023 (355) May 2023 (214) April 2023 (135) March 2023 (143) February 2023 (181) January 2023 (267) December 2022 (133) November 2022 (243) October 2022 (162) September 2022 (164) August 2022 (486) July 2022 (291) June 2022 (251) Menu Halaman Statis Beranda © 2022 - javascript dozent