Pass a value from javascript to bootstrap modal view - javascript

I've got a google table that listens to a select event and then shows a modal bootstrap. Is it possible to have my modal text display data from the selected row?
google.visualization.events.addListener(table, 'select', function () {
var row = table.getSelection()[0].row;
alert(data.getValue(row, 0))
$("#myModal").modal();
});
The alert shows the string I want in my modal window as well.
With the following modal:
<div id="myModal" class="modal fade" 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">Modal Header</h4>
</div>
<div class="modal-body edit-content">
<p id='inputId'>Display text here.</p>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>

Try
var modalcontent = data.getValue(row, 0);
$("#inputId").html(modalcontent);
right before $("#myModal").modal();
Here you can find the doc for this method.

Related

Allow background activities when loading bootstrap modal on page load

I want a bootstrap modal to appear on the bottom left corner of the page on page load and allow it to disappear only when the x button is clicked and not when clicked anywhere on the screen. I have got these working till now but the next issue is that when the bootstrap modal is loaded it prevents any background activity like page scrolling or link clicking or any such thing and adds a background shade with opacity in front of the screen. How can I make the shade disappear and allow accessing the website while the modal is loaded and displayed in the bottom left corner?
Here are my codes.
<script>
$(document).ready(function() {
$(window).on('load',function(){
$('#myModal').modal('show');
});
$('#myModal').modal({
backdrop: 'static',
keyboard: false
});
});
</script>
<div id="myModal" class="modal fade" role="dialog">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">×</button>
<h4 class="modal-title">Modal Header</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>
Sounds like your not after a modal dialog, but something that looks like one.
You can still render a modal, but don't call .modal on in, and then just handle the close events yourself.
eg.
$(document).ready(function() {
$(window).on('load',function(){
var m = $('#myModal');
m.show();
m.find("button").on("click",
function () { m.hide(); });
});
});
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.0/css/bootstrap.min.css" rel="stylesheet"/>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id="myModal" class="modal show" role="dialog">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<h4 class="modal-title">Modal Header</h4>
<button type="button" class="close" data-dismiss="modal">×</button>
</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>

display bootstrap modal popup from javascript not working

I am trying to open a modal popup from a javascript block. This is a basic modal that I found in w3schools: http://www.w3schools.com/bootstrap/tryit.asp?filename=trybs_ref_js_modal&stacked=h
Here is my code :
<script>
function showModal(){
window.location.href = '#myModal';
}
</script>
<!-- Modal -->
<div class="modal fade" id="myModal" 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">Modal Header</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>
Instead of JavaScript you an use default bootstrap function
function showModal(){
$('#myModal').modal('show')
}
window.location.href does not have what is known as a setter, which means it cannot be assigned a new value. It does have a getter as standard (a requirement, really), so you can get it.
If you want to open a link, try window.open("#myModal");, or use jQuery with $('#myModal').modal('show');

make modal popup while clicking on menu

I have a simple html design with an animated menu. I am trying to implement bootstrap on it and make modal window. But when someone clicks at contact, my animated menu stops working. Here you can check the problem.
My modal code here. I'm using #mymodal on menu link.
<!-- Trigger the modal with a button -->
<button type="button" class="btn btn-info btn-lg" data-toggle="modal" data-target="#myModal">Open Modal</button>
<!-- Modal -->
<div id="myModal" class="modal fade" 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">Modal Header</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>
You can do this using Jquery
$(document).on("click",".menu",function(){
$("#myModal").modal("show")
})

modal on appears after each item is clicked..can only loop the first item,then function doesnt work

I wanted to create as pop up modal after each button has been clicked on saying, you have clicked on all the buttons. I got the modal window to pop up with just one button but I cannot get the the rest of the other buttons to load when I create the same class. Please help,thanks
<div class="container">
<!-- Trigger the modal with a button -->
<button type="button" class="btn btn-info btn-lg" id="myBtn">Open Modal</button>
<!-- Modal -->
<div class="mybox modal fade" id="myModal" role="dialog">
<div class="modal-dialog">
<!-- Modal content-->
<div class=" mybox modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">×</button>
<h4 class="modal-title">Modal Header</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="win" 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">You won</h4>
</div>
<div class="modal-body">
<p>Congrats.</p>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
</div>
<script>
var Boxes = [];
var ttle = $('.mybox').length;
$('.mybox').click(function () {
var bx = this.id;
if (Boxes.indexOf(bx) >= 0) {
$("#myMod").modal("toggle");
} else {
Boxes.push(bx);
}
if (Boxes.length == ttle) {
$("#win").modal("toggle");
}
});
$(document).ready(function(){
$("#myBtn").click(function(){
$("#myModal").modal();
});
});
</script>

display a Modal or a dialog when a button is clicked in infowindow in javascript?

I have to display a new modal when a button is clicked in the infowindow. When I click MORE button in info window a modal should appear with more information regarding the marker while disabling the background.
I have tried in the following way but it is not working:
<!-- Modal -->
<div id="myModal" class="modal fade" 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">Modal Header</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>
I have added a button in info window to display the modal:
<button type="button" class="btn btn-info btn-lg" data-toggle="modal" data-target="#myModal">Open Modal</button>
But the above code is not working.

Categories

Resources