.click() sometimes works and sometimes does not - javascript

the problem I am having is I am trying to apply a click function on a div to a element inside a iframe, it works sometimes but sometimes it doesn't work and it's very random. Here is my code where I apply the click method:
<script type="text/javascript">
var yammerFrame = parent.parent.document.getElementsByTagName("frame")[1].contentDocument.getElementsByTagName("frame")[0].contentDocument.getElementsByTagName("iframe")[0];
$(yammerFrame).load(function() {
var yammerMessages = parent.parent.document.getElementsByTagName("frame")[1].contentDocument.getElementsByTagName("frame")[0].contentDocument.getElementsByTagName("iframe")[0].contentWindow.document.getElementById('yammerMessages');
$(document).ready(function() {
$(yammerMessages).click(function() {
$('#myModal').modal('show');
});
});
});
</script>
<div id="myModal" class="modal fade" role="dialog">
<div class="modal-dialog">
<!-- Modal content-->
<div class="modal-content">
<div class="modal-header" style="text-align: center">
<button type="button" class="close" data-dismiss="modal">×</button>
<span>
<img src="https://upload.wikimedia.org/wikipedia/commons/1/1f/Yammer_logo.png" alt="Yammer" style="width: 200px;height: 50px;">
</span>
</div>
<div class="modal-body" style="text-align: center">
<h4 id="modal-body-sender" style="font-weight:bold"></h4>
<h4 id="modal-body-date"></h4>
<div id="modal-body-well" class="well">
<h4 id="modal-body-message" style="color:black;word-wrap: break-word;"></h4>
</div>
</div>
<div class="modal-footer">
<div class="btn-group" role="group" aria-label="...">
<button type="button" class="btn btn-primary" onclick="open_win()">Go To Post</button>
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
</div>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css" type="text/css" />
<link rel="stylesheet" href="css/Site.css" type="text/css" />
</head>
<body>
<span id="yammer-login"></span>
<div id="yammerDiv">
<div id="yammerHeader">
<img src="https://upload.wikimedia.org/wikipedia/commons/1/1f/Yammer_logo.png" alt="Yammer" height="17px;" width="50%">
</div>
<div id="yammerMessages" style="margin-top: 25px;">
<img id="loading-gif" src="http://i559.photobucket.com/albums/ss36/madszckey01/speakker/buffering.gif">
<div id="text-wrapper" style="width: 100%; height: 76%;">
<span id="message"></span>
</div>
<span id="sender"></span>
</div>
<div id="yammerButtons" style="display:none">
<button id="previous" type="button" class="btn btn-default btn-xs" aria-label="Left Align" onclick="onPrevious()" dataenter code here-toggle='tooltip' data-placement='top' data-original-title="Previous">
<span class="glyphicon glyphicon-chevron-left" aria-hidden="true"></span>
</button>
<input type="checkbox" id="myCheck" onclick="autoscroll()" data-toggle='tooltip' data-placement='top' data-original-title="Auto-Scroll" class='checkbox'>
<button id="next" type="button" class="btn btn-default btn-xs" aria-label="Right Align" onclick="onNext()" data-toggle='tooltip' data-placement='top' data-original-title="Next">
<span class="glyphicon glyphicon-chevron-right" aria-hidden="true"></span>
</button>
</div>
</div>

Try this function with live.
$(yammerMessages).live('click', function() {
$('#myModal').modal('show');
});

Related

ajax post list update only first of posts

I have a list of content that users send, such as tweeting, and they post a text, and the following content is also displayed. input I put an ID that updates that ID in Ajax, but because the posts are below and editing is modal, only one of the forms can be edited because the input ID is fixed
Can you please help?
#foreach($consult as $item)
<div id="cards" class="card data-id-{{$item->id}}">
<div class="card-header">
<h5 class="card-title">your consult</h5>
<div class="card-tools">
<button type="button" class="btn btn-tool" data-card-widget="collapse">
<i class="fas fa-minus"></i>
</button>
<div class="btn-group">
<button type="button" class="btn btn-tool " data-toggle="dropdown" aria-expanded="false">
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" data-supported-dps="24x24" fill="currentColor" class="mercado-match" width="24" height="24" focusable="false">
<path d="M14 12a2 2 0 11-2-2 2 2 0 012 2zM4 10a2 2 0 102 2 2 2 0 00-2-2zm16 0a2 2 0 102 2 2 2 0 00-2-2z"></path>
</svg>
</button>
<div class="dropdown-menu dropdown-menu-right" role="menu" style="">
<button data-toggle="modal" data-target="#modal-lg-{{$item->id}}" class="dropdown-item "><i class="fas fa-edit"></i> Edit</button>
<button class="dropdown-item deleteskill" data-id="{{$item->id}}" data-token="{{ csrf_token() }}" ><i class="fas fa-trash"></i> Delete</button>
</div>
</div>
</div>
</div>
<div class="card-body" >
<div class="post">
<div class="user-block all-posts-body">
#if(Auth::user()->photo)
<img alt="On Demand Consults" class="img-circle img-bordered-sm" src="/photo/avatar/{{Auth::user()->photo}}">
#else
<img alt="On Demand Consults" class="img-circle img-bordered-sm" src="/img/avatar.png" >
#endif
<span class="username">
{{Auth::user()->name}}{{Auth::user()->family}}
</span>
<span class="description">Shared publicly - {{ \Carbon\Carbon::parse($item->created_at)->diffForhumans()}}</span>
<p>
{{$item->description}}
</p>
</div>
</div>
</div>
</div>
#endforeach
my modal
#foreach($consult as $item)
<div class="modal fade" id="modal-lg-{{$item->id}}">
<div class="modal-dialog modal-lg">
<div class="modal-content">
<div class="modal-header">
<h4 class="modal-title">update your consult</h4>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<form data-id="{{$item->id}}" method="post" action="{{ route("Consult.update", $item->id) }}" enctype="multipart/form-data">
#csrf
#method('PUT')
<div class="modal-body">
<textarea id="description" name="description" class="form-control form-control-sm" type="text" placeholder="What do you want to talk about?" >{{$item->description}}</textarea>
<div class="alert-message" id="descriptiError"></div>
</div>
<div class="modal-footer justify-content-between">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
<button type="button" class="btn btn-primary updateInfo" data-id="{{$item->id}}" data-token="{{ csrf_token() }}">Save changes</button>
</div>
</form>
</div>
<!-- /.modal-content -->
</div>
<!-- /.modal-dialog -->
</div>
#endforeach
my ajax code
$(".updateInfo").on('click',function(e) {
e.preventDefault();
let description = $('#description').val();
const ConsultId = $(this).attr('data-id');
var confirmation = confirm("Are you sure you want to update this Consult ?");
if (confirmation) {
$.ajax({
type:"PUT",
data:{
"_token": "{{ csrf_token() }}",
description:description,
},
url:'/ConsultantsCp/Consult/' + ConsultId,
success: function(data){
swal({title: "Good job", text: "Consult is successfully updated!", type:
"success", timer: 1500, buttons: false,}).then(function(){
location.reload();
}
);
},
error: function(response) {
$('#descriptiError').text(response.responseJSON.errors.description);
}
});
}
});
enter image description here
enter image description here
Similar as Rateb's answer, however a bit different
First we have to declare a javascript function to initialize whatever we need to show in the modal form
Second we must call the function with the necessary content. In your case when we click the Edit button, it must cal the js function
Third is the logic you use to post the data.
Notice how i have encoded the description to preserve the format and i have deleted the other parameters in the modal form and declared a hidden field to contain the item-id.
#foreach($consult as $item)
<div id="cards" class="card data-id-{{$item->id}}">
<div class="card-header">
<h5 class="card-title">your consult</h5>
<div class="card-tools">
<button type="button" class="btn btn-tool" data-card-widget="collapse">
<i class="fas fa-minus"></i>
</button>
<div class="btn-group">
<button type="button" class="btn btn-tool " data-toggle="dropdown" aria-expanded="false">
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" data-supported-dps="24x24" fill="currentColor" class="mercado-match" width="24" height="24" focusable="false">
<path d="M14 12a2 2 0 11-2-2 2 2 0 012 2zM4 10a2 2 0 102 2 2 2 0 00-2-2zm16 0a2 2 0 102 2 2 2 0 00-2-2z"></path>
</svg>
</button>
<div class="dropdown-menu dropdown-menu-right" role="menu" style="">
<button data-toggle="modal" data-target="#edit-modal" onclick="initModal({{$item->id}}, {{json_encode($item->description)}} )" class="dropdown-item "><i class="fas fa-edit"></i> Edit</button>
<button class="dropdown-item deleteskill" data-id="{{$item->id}}" data-token="{{ csrf_token() }}" ><i class="fas fa-trash"></i> Delete</button>
</div>
</div>
</div>
</div>
<div class="card-body" >
<div class="post">
<div class="user-block all-posts-body">
#if(Auth::user()->photo)
<img alt="On Demand Consults" class="img-circle img-bordered-sm" src="/photo/avatar/{{Auth::user()->photo}}">
#else
<img alt="On Demand Consults" class="img-circle img-bordered-sm" src="/img/avatar.png" >
#endif
<span class="username">
{{Auth::user()->name}}{{Auth::user()->family}}
</span>
<span class="description">Shared publicly - {{ \Carbon\Carbon::parse($item->created_at)->diffForhumans()}}</span>
<p>
{{$item->description}}
</p>
</div>
</div>
</div>
</div>
#endforeach
modal
<div class="modal fade" id="edit-modal">
<div class="modal-dialog modal-lg">
<div class="modal-content">
<div class="modal-header">
<h4 class="modal-title">update your consult</h4>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<form id="edit-modal-form">
<div class="modal-body">
<textarea id="description" name="description" class="form-control form-control-sm" type="text" placeholder="What do you want to talk about?" ></textarea>
<div class="alert-message" id="descriptiError"></div>
<input type="hidden" id="item-id-field">
</div>
<div class="modal-footer justify-content-between">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
<button type="submit" class="btn btn-primary updateInfo" >Save changes</button>
</div>
</form>
</div>
<!-- /.modal-content -->
</div>
<!-- /.modal-dialog -->
</div>
scripts
function initModal(id, description)
{
// Inialize the modal hidden field with the id value using Jquery
$("#item-id-field").val(id);
// decode the json and show it in the desciption field in the modal
var description_decoded = JSON.parse(JSON.stringify(description));
$("#description").html(description_decoded);
}
$(".updateInfo").on('click',function(e) {
e.preventDefault();
let description = $('#description').val();
const ConsultId = $("#item-id-field").val();
var confirmation = confirm("Are you sure you want to update this Consult ?");
if (confirmation) {
$.ajax({
type:"PUT",
data:{
"_token": "{{ csrf_token() }}",
description:description,
},
url:'/ConsultantsCp/Consult/' + ConsultId,
success: function(data){
swal({title: "Good job", text: "Consult is successfully updated!", type:
"success", timer: 1500, buttons: false,}).then(function(){
location.reload();
}
);
},
error: function(response) {
$('#descriptiError').text(response.responseJSON.errors.description);
}
});
}
});
Try this example, it's a simple example assuming you have show route that gives the post info and edit route that submitting the edits, in this example we are not submitting form we just sending a request with ajax client called axios,
The blade file:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css"
integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
</head>
<body>
#foreach($consult as $item)
<div id="cards" class="card">
<div class="card-header">
<h5 class="card-title">your consult</h5>
<div class="card-tools">
<button type="button" class="btn btn-tool" data-card-widget="collapse">
<i class="fas fa-minus"></i>
</button>
<button data-id={{$item['id']}} type="button" class="btn btn-primary" data-toggle="modal" data-target="#exampleModal">
edit
</button>
</div>
</div>
<div class="card-body">
<div class="post">
<p>
{{$item['description']}}
</p>
</div>
</div>
</div>
#endforeach
<div class="modal fade" id="exampleModal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel"
aria-hidden="true">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="exampleModalLabel">Edit post</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body">
<form>
<input type="hidden" name="id">
<div class="form-group">
<label>Description</label>
<input name="description" class="form-control">
</div>
</form>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
<button name="save-button" type="button" class="btn btn-primary">Save changes</button>
</div>
</div>
</div>
</div>
<script src="https://code.jquery.com/jquery-3.2.1.slim.min.js"
integrity="sha384-KJ3o2DKtIkvYIK3UENzmM7KCkRr/rE9/Qpg6aAZGJwFDMVNA/GpGFF93hXpG5KkN" crossorigin="anonymous">
</script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js"
integrity="sha384-ApNbgh9B+Y1QKtv3Rn7W3mgPxhU9K/ScQsAP7hUibX39j7fakFPskvXusvfa0b4Q" crossorigin="anonymous">
</script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js"
integrity="sha384-JZR6Spejh4U02d8jOt6vLEHfe/JQGiRRSQQxSfFWpi1MquVdAyjUar5+76PVCmYl" crossorigin="anonymous">
</script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/axios/0.21.4/axios.min.js"></script>
</body>
<script>
const modal = $('#exampleModal')
const descriptionInput = $('input[name="description"]')
const idInput = $('input[name="id"]')
const saveButton = $('button[name="save-button"]')
modal.on('show.bs.modal', (e) => {
// getting the id from clicked button
const postId = e.relatedTarget.getAttribute('data-id')
// render the required post info
axios.get('/posts/' + postId).then(res => {
descriptionInput.val(res.data.description)
idInput.val(res.data.id)
})
})
saveButton.on('click', () => {
// the edit request in your example its /ConsultantsCp/Consult/' + ConsultId
axios.put('/posts/' + idInput.val(), {
_token: "{{ csrf_token() }}",
description: descriptionInput.val(),
}).then(res => {
console.log(res)
modal.modal('toggle')
})
})
</script>
</html>

Bootstrap modal does not open

I have a modal in my html file that I want to trigger with a button.
My button is inside a table. This is the code of my button:
<button type="button" class="btn btn-outline-primary"
data-toggle="modal" data-target="#squarespaceModal" >
<!-- [routerLink]="['/function', bfunc.AName]" -->
<i class="fa fa-pencil" aria-hidden="true"></i>
</button>
And this is my modal-code in the same html-file:
<!-- line modal -->
<div class="modal fade" id="squarespaceModal" tabindex="-1" role="dialog" aria-labelledby="modalLabel" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">×</span><span class="sr-only">Close</span></button>
<h3 class="modal-title" id="lineModalLabel">My Modal</h3>
</div>
<div class="modal-body">
<!-- content goes here -->
</div>
<div class="modal-footer">
<div class="btn-group btn-group-justified" role="group" aria-label="group button">
<div class="btn-group" role="group">
<button type="button" class="btn btn-default" data-dismiss="modal" role="button">Close</button>
</div>
<div class="btn-group btn-delete hidden" role="group">
<button type="button" id="delImage" class="btn btn-default btn-hover-red" data-dismiss="modal" role="button">Delete</button>
</div>
<div class="btn-group" role="group">
<button type="button" id="saveImage" class="btn btn-default btn-hover-green" data-action="save" role="button">Save</button>
</div>
</div>
</div>
</div>
</div>
</div>
When I hit the button nothing happens.
I checked the console but there are no errors
Can anyone help me please?
EDIT:
I have imported these scripts in my index.html
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
You need to import the bootstrap css https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.7/css/bootstrap.min.css
As was mentioned you need to ensure that all resources (js, css, jquery) are imported in order to get the modal to work. Here's a simple html file with the modal code and all resources in the head.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
<link rel="stylesheet" href="css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script src="js/bootstrap.min.js"></script>
</head>
<body>
<!-- Button trigger modal -->
<button type="button" class="btn btn-primary" data-toggle="modal" data-target="#exampleModal"> Launch demo modal </button>
<!-- Modal -->
<div class="modal fade" id="exampleModal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="exampleModalLabel">Modal title</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close"> <span aria-hidden="true">×</span> </button>
</div>
<div class="modal-body"> ... </div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
<button type="button" class="btn btn-primary">Save changes</button>
</div>
</div>
</div>
</div>
</body>
</html>

Pre-populate modal textarea with text

Currently a button opens a modal that includes a text box. I need have that text box pre-populated, so I have attempted to mess around with the modal with no luck.
I have tried the following and nothing appears to happen.
function testFunc(){
$('#contactUsDlg').modal('show');
$('#contactUsDlg').on('shown.bs.modal', function {
$('#message-text').text("test");
});
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<button type="button" name="btn-ask" id="nonconform-btn" data-form-action-url="${newMessageUrl}"
data-pns="<%=OrderStatusPortletConstants.MESSAGE_CENTER_PORTLET_NAMESPACE %>"
data-use-ajax="true"
class="btn btn-submit btn-ask contact-us-dlg"
data-hidden-fields="message-order-id,message-source-url"
data-message-order-id="${selectedOrder.id}" data-message-source-url="${sourceUrl}" >
Contact Us
</button>
This is a possible solution basen on your snippets (not complete, IMHO)
$(document).ready(function() {
$('#contactUsModal').on('show.bs.modal', function(e) {
var text = $(e.relatedTarget).data('default-text');
$(this).find('#message-text').text(text);
});
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<link rel="stylesheet" type="text/css" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<link rel="stylesheet" type="text/css" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap-theme.min.css">
<button type="button" name="btn-ask" class="btn btn-submit btn-ask contact-us-dlg" data-form-action-url="${newMessageUrl}" data-pns="<%=OrderStatusPortletConstants.MESSAGE_CENTER_PORTLET_NAMESPACE %>" data-use-ajax="true" data-hidden-fields="message-order-id,message-source-url"
data-message-order-id="${selectedOrder.id}" data-message-source-url="${sourceUrl}" data-toggle="modal" data-target="#contactUsModal" data-default-text="Initial contact us textarea modal content">
Contact Us
</button>
<div class="modal fade" id="contactUsModal" tabindex="-1" role="dialog" aria-labelledby="contactUsModalLabel">
<div class="modal-dialog" role="document">
<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="exampleModalLabel">New message</h4>
</div>
<div class="modal-body">
<form>
<div class="form-group">
<label for="recipient-name" class="control-label">Recipient:</label>
<input type="text" class="form-control" id="recipient-name">
</div>
<div class="form-group">
<label for="message-text" class="control-label">Message:</label>
<textarea class="form-control" id="message-text"></textarea>
</div>
</form>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
<button type="button" class="btn btn-primary">Send message</button>
</div>
</div>
</div>
</div>
If you haven't already, you should look into using jQuery UI. Here you can use something like the following:
<script src='jquery-3.2.1.min.js'></script>
<script src='jquery-ui-1.12.1.custom/jquery-ui.js'></script>
<link href='jquery-ui-1.12.1.custom/jquery-ui.css' rel='stylesheet' type='text/css'></link>
<link href='jquery-ui-1.12.1.custom/jquery-ui.theme.css' rel='stylesheet' type='text/css'></link>
<input id='mybutton' type='button' value='click me' />
<div id='result'>
<p id='firstp'></p>
<p id='secondp'></p>
</div>
<script>
$(function() {
$('#result').dialog({
open: function(event, ui) {
$('#resultp').html('[this is my text]');
}
});
});
$('#mybutton').on('click', function(evt) {
$('#secondp').html('[this is my second text]');
});
</script>

Modal does not close

When pressing the "Confirm" button, it executes the function and the action, but the event of closing the modal does not execute it.
This is my code:
<script type="text/javascript">
$("document").ready(function() {
var actsel = $("#act_selected").val();
$("#habilitaract_mensaje").html("¿You want to end the activity No. <strong>" + actsel + "</strong>?");
$("#btn_actconfirmar").click(function() {
if (habHabitacion()) {
$('#modal_habilitaract').modal('hide');
}
});
});
</script>
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal"><span>×</span></button>
<h4 class="modal-title">Enable Activity</h4>
</div>
<div class="modal-body">
<h5><span id="habilitaract_mensaje"></span></h5>
<br>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-primary" id="btn_actconfirmar">
<span class="texto-sm"><span class="glyphicon glyphicon-ok"></span> Confirm</span>
</button>
</div>
I think the problem comes from your import of bootstrapp or the definition of the div of the modal
Look at mine:it works correctly
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.2.0/jquery.min.js"></script>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" />
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>
<script type="text/javascript">
$("document").ready(function() {
var actsel = $("#act_selected").val();
$("#habilitaract_mensaje").html("¿You want to end the activity No. <strong>" + actsel + "</strong>?");
$("#btn_actconfirmar").click(function() {
alert("welcome");
});
});
</script>
<div align="right">
<button type="button" name="add" id="add" data-toggle="modal" data-target="#add_data_Modal" class="btn btn-warning">Add</button>
</div>
<div id="add_data_Modal" class="modal fade">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal"><span>×
</span></button>
<h4 class="modal-title">Enable Activity</h4>
</div>
<div class="modal-body">
<h5><span id="habilitaract_mensaje"></span></h5>
<br>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-primary" id="btn_actconfirmar">
<span class="texto-sm"><span class="glyphicon glyphicon-ok"></span> Confirm</span>
</button>
</div>
</div>
</div>
</div>
If habHabitacion function returns boolean true then modal window should be close. Please check what habHabitacion return.

Bootstrap Collapse Widget not working

I need to have used Collapse in bootstrap to hide some information and display once button is click but I don't know that wrong on this one why it is not working.
<div id="myModal6" class="modal fade mdl" role="dialog">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">×</button>
<h2 class="modal-title title_modal">Sample Data
<span data-widget="collapse" tabindex="0" class="toggle-collapsed ui-collapse ui-toggle pull-right btn_details" role="button" aria-controls="toggle-pane-88" id="toggle-89" aria-expanded="false">Toggle</span>
</h2>
</div>
<div class="modal-body">
<p class="toggle-collapsed" aria-hidden="true" id="toggle-pane-88" aria-expanded="false" aria-labelledby="toggle-89">This is my content!
</p>
<div class="row">
<div class="col-md-6">
<p class="headline_text">Sample again</p>
<p style="text-align:center"><img src="img/samp.jpg"
</div>
<div class="col-md-6">
<p class="headline_text"> </p>
<p style="text-align:center"><img src="img/samp21.jpg"/> </p>
</div>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
I also include here files needed in bootstrap:
<link href="bootstrap/css/bootstrap.min.css" rel="stylesheet" type="text/css" />
<link href="https://maxcdn.bootstrapcdn.com/font-awesome/4.3.0/css/font-awesome.min.css" rel="stylesheet" type="text/css" />
<script src="plugins/jQuery/jQuery-2.1.4.min.js"></script>
<script src="https://code.jquery.com/ui/1.11.4/jquery-ui.min.js" type="text/javascript"></script>
<script src="bootstrap/js/bootstrap.min.js" type="text/javascript"></script>
<script src="js/script.js" type="text/javascript"></script>
<script src="dist/js/app.min.js" type="text/javascript"></script>
If you are just trying to put a collapse panel inside your modal you need to add a target div for #toggle-pane-88. See example.
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"></script>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css" rel="stylesheet" />
<button type="button" class="btn btn-info btn-lg" data-toggle="modal" data-target="#myModal">Open Modal</button>
<div id="myModal" class="modal fade mdl" role="dialog">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">×</button>
<h2 class="modal-title title_modal">Sample Data
<span data-widget="collapse" tabindex="0" class="toggle-collapsed ui-collapse ui-toggle pull-right btn_details" role="button" aria-controls="toggle-pane-88" id="toggle-89" aria-expanded="false">Toggle</span>
</h2>
</div>
<div class="modal-body">
<button type="button" class="btn btn-info" data-toggle="collapse" data-target="#toggle-pane-88">Simple collapsible</button>
<div id="toggle-pane-88" class="collapse">
<p class="headline_text">Sample again</p>
<p style="text-align:center">
<img src="img/samp.jpg" </div>
<p class="headline_text"> </p>
<p style="text-align:center">
<img src="img/samp21.jpg" />
</p>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
</div>

Categories

Resources