How to pass value into href link of a Bootstrap Modal?
Use the following lines of code inside your script tag and this should work fine.
$('#scrapModal .btn-danger').on('click', function (e) {
e.preventDefault()
alert(e.target.pathname + e.target.search)
})
pass id to a tag href in modal(bootstrap)
So do something like
<a type="button" id="down" data-href="<?php echo base_url(); ?>/aprove/download/">Berkas</a>
and read the data attribute
var anchor = modal.find('#down')
anchor.attr('href', anchor.data('href') + div.data('id'));
Pass data to modal from other url
You are already using the *data
attributes in your html page. All you have to do is to add few more data-* id's according to your need to pass the data from your parent html page to the popup page.
For eg,
Considering your case you can pass the name and description to your modal like this,
<a href="v?PageId=frmGroupGeneral" data-toggle="modal" data-name="YOUR_NAME_VALUE" data-description="YOUR_DESCRIPTION" data-target="#editGroup">EDIT</a>
And in your modal you can retrieve the passed in parameters as,
var nameValue = $(this).data('name');
var descriptionValue = $(this).data('description');
To set the retrieved value to any field in model you can simply do,
$(".modal-body #textareaName").val(nameValue);
$(".modal-body #textareaDescription").val(descriptionValue);
Hope this helps!
How to pass variables to a modal from a link
I think you should render all of your modals at the bottom of the page and use jQuery to to load the modal associated to the link.
e.g.
<button type="button" class="btn btn-info btn-lg" id="myBtn1">Open Modal 1</button>
Then bind bootstraps .modal() function to the button's click event with jQuery. This is where you can set which modal to load eg.
$("#myBtn1").click(function(){
$("#myModal1").modal();
});
Please run my code snippet which I have modified from w3 schools documentation
<!DOCTYPE html><html lang="en"><head> <title>Bootstrap Example</title> <meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1"> <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css"> <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.0/jquery.min.js"></script> <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script></head><body>
<div class="container"> <h2>Activate multiple Modal with JavaScript</h2> <!-- Trigger the modal with a button --> <button type="button" class="btn btn-info btn-lg" id="myBtn1">Open Modal 1</button> <button type="button" class="btn btn-success btn-lg" id="myBtn2">Open Modal 2</button>
<!-- Modal --> <div class="modal fade" id="myModal1" role="dialog"> <div class="modal-dialog"> <!-- Modal content--> <div class="modal-content"> <div class="modal-header"> <button type="button" class="close" data-dismiss="modal">×</button> <h4 class="modal-title">Look its modal one</h4> </div> <div class="modal-body"> <p>Some text in the modal.</p> </div> <div class="modal-footer"> <button type="button" class="btn btn-default" data-dismiss="modal">Close</button> </div> </div> </div> </div> <div class="modal fade" id="myModal2" role="dialog"> <div class="modal-dialog"> <!-- Modal content--> <div class="modal-content"> <div class="modal-header"> <button type="button" class="close" data-dismiss="modal">×</button> <h4 class="modal-title">look its modal 2</h4> </div> <div class="modal-body"> <p>Some text in the modal.</p> </div> <div class="modal-footer"> <button type="button" class="btn btn-default" data-dismiss="modal">Close</button> </div> </div> </div> </div> </div>
<script>$(document).ready(function(){ $("#myBtn1").click(function(){ $("#myModal1").modal(); }); $("#myBtn2").click(function(){ $("#myModal2").modal(); });});</script>
</body></html>
How to pass a parameter from a link element to a modal window?
Use the .relatedTarget
property mentioned in the Modal Event docs:
$(document).ready(function () {
$('#remoteModal').on('show.bs.modal', function (event) {
console.log($(event.relatedTarget).attr('data-id'));
});
});
Related Topics
Can We Call the Function Written in One JavaScript in Another Js File
How to Let a User Download Multiple Files When a Button Is Clicked
Show Form Fields Based on Selected Option
How to Set an Iframe Src Attribute from a Variable in Angularjs
Progressive Web App - Service Worker Not Serving Start_Url
415 (Unsupported Media Type) With Rest Post Request
Process a Dictionary and Return Each Entry in React
Get an Attribute from the Clicked Element With JavaScript
Replacing Multiple Elements of an Array While Keeping Their Position
Finding Sequential Values in Js Array
Connection Refused! Is Selenium Server Started
Element Implicitly Has an 'Any' Type Because Index Expression Is Not of Type 'Number' [7015]
Converting Excel Date Serial Number to Date Using JavaScript
Call Ajax or Submit the Button When Checkbox Is Checked
Angular 4 Submit Form by Pressing Enter With Login Button
Display Image from Http Response With Image Content Type
Why New Date().Toisostring() Is Loosing Timezone
Bootstrap Carousel: How to Stop Auto Sliding on Large Screen