To open a modal window, you should use data-toggle="modal" and href. If it's not <a>, you can use data-target instead:
data-toggle="modal" data-target="#exampleModal"
To pass a unique value to the modal, you need to use data-* attributes. This can be given to the modal handler like this:
<button type="button" class="btn btn-primary" data-toggle="modal" data-target="#exampleModal" data-whatever="@mdo">Open modal for @mdo</button>
<button type="button" class="btn btn-primary" data-toggle="modal" data-target="#exampleModal" data-whatever="@fat">Open modal for @fat</button>
<button type="button" class="btn btn-primary" data-toggle="modal" data-target="#exampleModal" data-whatever="@getbootstrap">Open modal for @getbootstrap</button>
The next thing is that, you need to handle the custom input. Once the modal window is shown, you need to execute some stuff. For that, you need to assign an event handler, once the modal window is shown:
// Execute something when the modal window is shown.
$('#exampleModal').on('show.bs.modal', function (event) {
var button = $(event.relatedTarget); // Button that triggered the modal
var recipient = button.data('whatever'); // Extract info from data-* attributes
// If necessary, you could initiate an AJAX request here (and then do the updating in a callback).
// Update the modal's content. We'll use jQuery here, but you could use a data binding library or other methods instead.
var modal = $(this);
modal.find('.modal-title').text('New message to ' + recipient);
modal.find('.modal-body input').val(recipient);
});
The issues with your code:
- Assigning multiple elements with same
idis a crime. Do not reuseidas they are unique. - You need to assign the
data-toggleto the<a>tag. - You should pass the attributes through
data-*attributes.
Working Snippet
$(function () {
$('#myModal').on('show.bs.modal', function (event) {
var button = $(event.relatedTarget); // Button that triggered the modal
var code = button.data('code'); // Extract info from data-* attributes
var company = button.data('company'); // Extract info from data-* attributes
// If necessary, you could initiate an AJAX request here (and then do the updating in a callback).
// Update the modal's content. We'll use jQuery here, but you could use a data binding library or other methods instead.
var modal = $(this);
modal.find('#code').val(code);
modal.find('#company').val(company);
});
});
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<script src="https://code.jquery.com/jquery-2.2.4.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<a href="#myModal" class="btn btn-info btn-lg" data-toggle="modal" data-code="code" data-company="company name">
<img src="../images/edit.png" style="width:20px;">
</a>
<div class="modal fade bs-example-modal-sm" tabindex="-1" id="myModal">
<div class="modal-dialog modal-sm">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
<h4 class="modal-title" id="mySmallModalLabel">Codes & Company</h4>
</div>
<div class="modal-body">
<input type="text" id="code" readonly />
<input type="text" id="company" readonly />
</div>
</div>
</div>
</div>
Please map your code with the above code. You don't need to change any other values. Just the way <span> is done.
Appsloveworld
appsloveworld.com › php › 593 › onclick-pass-value-to-popup-modal
Onclick pass value to popup modal - appsloveworld.com
To open a modal window, you should use data-toggle="modal" and href. If it's not <a>, you can use data-target instead: ... To pass a unique value to the modal, you need to use data-* attributes.
Videos
GeeksforGeeks
geeksforgeeks.org › how-to-pass-data-into-a-bootstrap-modal
How to Pass Data into a Bootstrap Modal? - GeeksforGeeks
To pass data into the modal body jQuery methods are used. In this approach, the web page consists of two input fields Name and Marks which accept input from the user. The data entered in the input fields are extracted using the IDs of the respective ...
Published July 29, 2024
W3Schools
w3schools.invisionzone.com › browser scripting › javascript
Passing parameters to modal dialog - W3Schools Forum
March 24, 2017 - I am using the W3Schools CSS/JS modal dialog example: https://www.w3schools.com/howto/howto_css_modals.asp However I would like to be able to pass a parameter from the button to the modal window as a variable so I can use it to perform a database query and populate the modal. I HAVE looked throug...
Microsoft
social.msdn.microsoft.com › Forums › en-US › 54c2eae9-8a83-4408-b672-c24b90cb318f › how-to-pass-variable-value-to-modal-in-javascript
How to pass variable value to Modal in Javascript | Microsoft Learn
October 5, 2018 - In class btn btn-danger value is ok. But in deleteconfirmModal it shows undefined · var Id; $(document).ready(function () { $('.btn.btn-danger').on('click', function () { var Id = $(this).data('id'); $('#deleteConfirmModal').modal('show'); }); $("#deleteConfirmModal").on('click', "#deleteConfirm", function () { debugger; console.log(Id); return false; }); });
Archlinux
copyprogramming.com › t › onclick-pass-value-to-popup-modal
Onclick Pass Value To Popup Modal - CopyProgramming
Solution: You don't really need to "pass data, .onclick = function() { modal2.textContent = 'different text!', > Solution 2: The best way is to pass, () { return row; } } }); }; And then pass, "> <button class="btn btn-success" id="change" onclick="func(this)" name="change"
Laracasts
laracasts.com › discuss › channels › laravel › how-to-pass-value-to-bootstrap-modal-window
How to pass value to bootstrap modal window ?
We cannot provide a description for this page right now
Stack Overflow
stackoverflow.com › questions › 62690181 › onclick-pass-value-to-popup-modal-laravel-jquery
onclick pass value to popup modal laravel jquery
July 2, 2020 - i'm trying to get data-staffId value in modal popup but on show.bs.modal event not working: $(function(){ $('#roasterManagementShifts').on('show.bs.modal',function(e){ var button = $(event.relatedTarget); var staffId = button.data('staffId') var model =$(this); var aro = modal.find('#staffId').val('staffId'); console.log(aro); }); }); Is there any better way to pass value to modal popup?
Stack Overflow
stackoverflow.com › questions › 41728926 › pass-data-to-modal-popup
Pass data to modal popup - javascript
You don't really need to "pass data" to the modal -- it's part of the window, and you can use Javascript to affect it in the same way you do the button. For example, if you wanted to change the text in the modal, you could just do: btn3.onclick ...
DaniWeb
daniweb.com › programming › web-development › threads › 538554 › how-to-pass-value-to-modal-popup-from-linkbutton-in-asp-net
How to pass value to modal popup from linkbutton in asp.net
September 4, 2022 - The original script has a syntax error and uses .val() on a LinkButton (anchors do not expose .val()), selecting #linkbutton1 won't reliably match buttons generated inside a GridView, and CommandArgument is a server-side property (not emitted as a client data-attribute). @Dani was right to point toward the modal show event, but the handler needs to read the element that actually triggered the modal.
Microsoft Learn
learn.microsoft.com › en-us › answers › questions › 929002 › asp-route-onclick-help
asp-route onclick help - Microsoft Q&A
So, to add additional data to the <a> tag, you can use custom attribute, like data-{value}. Then, in the hyperlink click event, find the custom attribute and append the value at the end of the request url: Then, the output as below: view the source code from here: 222976-sourcecode.txt · Finally, in the Ajax success function, you can show the popup modal.
CodeProject
codeproject.com › Questions › 5296055 › How-to-pass-data-from-one-page-to-another-by-oncli
[Solved] How to pass data from one page to another by onclick into a specific list? - CodeProject
March 1, 2021 - Free source code and tutorials for Software developers and Architects.; Updated: 1 Mar 2021
Team Treehouse
teamtreehouse.com › community › how-to-pass-a-variable-to-a-modal-from-the-button
How to pass a variable to a modal from the button. (Example) | Treehouse Community
June 10, 2017 - "'>\n"; $form .= "<input type='submit' class='btn btn-info' name='submitnew' value='Add Debt'>\n"; $form .= "</form></td>\n"; $form .= "</tr>\n"; $form .= "</table>\n"; $form .= "<!-- Trigger the modal with a button -->"; $form .= "<!-- Modal -->"; $form .= "<div id='myHistory' class='modal fade' role='dialog'>"; $form .= " <div class='modal-dialog modal-lg'>"; $form .= " <!-- Modal content-->"; $form .= " <div class='modal-content'>"; $form .= " <div class='modal-header'>"; $form .= " <button type='button' class='close' data-dismiss='modal'>×</button>"; $form .= " <h4 class='modal-title
GitHub
github.com › mpontus › react-modal-hook › issues › 2
Passing props to modal dialog · Issue #2 · mpontus/react-modal-hook
December 24, 2018 - let props = {}; export function setMyDialogProps(newprops) { props = newprops; } export default function MyDialog() { return ( <div role="dialog" className="modal"> <div className="modal-content"> <p>Modal content</p> <button onClick={props.hideDialog}>Hide modal</button> </div> </div> ); }
Author tgochenour
Flowbite React
flowbite-react.com › docs › components › modal
React Modal - Flowbite
</p> </div> </ModalBody> <ModalFooter> <Button onClick={() => setOpenModal(false)}>I accept</Button> <Button color="alternative" onClick={() => setOpenModal(false)}> Decline </Button> </ModalFooter> </Modal> </> ); }Expand code · Use this example by passing the popup prop from React to the modal component to show a dialog to the user asking for a decision such as when confirming an item deletion from the database.
Experts Exchange
experts-exchange.com › questions › 28703133 › Declare-value-of-variable-and-pass-it-to-form-value-modal-window-jquery.html
Solved: Declare value of variable and pass it to form value. (modal window/jquery) | Experts Exchange
August 5, 2015 - You have to manually populate the ... what you have done for the idfield - retrieve the values you need to populate and then set the corresponding field values (by id) in the modal form....