bootstrap modal.js last complete button missing - javascript

I'm just trying to learn modal.js I'm expecting that at the last page(data-step=3), I would see a finish button and when i click on that, it'll close the modal. But the problem here is, at the last page, only the cancel and previous button is visible. The next button is hidden, which is fine but i thought it would be replaced by the finish button. What am i missing here?
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">
<title>WhyQ</title>
<link href="http://fonts.googleapis.com/css?family=Titillium+Web:400,400italic,700" rel="stylesheet" type="text/css">
<link href="//maxcdn.bootstrapcdn.com/font-awesome/4.2.0/css/font-awesome.min.css" rel="stylesheet">
<link rel="stylesheet" type="text/css" href="css/bootstrap.min.css">
<link rel="stylesheet" type="text/css" href="css/style.css">
<link rel="stylesheet" type="text/css" href="css/style-o.css">
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script>
<script type="text/javascript" src="js/bootstrap.min.js"></script>
<script type="text/javascript" src="js/scripts.js"></script>
</head>
<body>
<div id='tab-shopping-cart' class="order-nav-tab" data-toggle="modal" data-target="#cartModal">
<div class="order-nav-shopping-cart">Click here</div>
</div>
<div class="modal fade" id="cartModal" tabindex="-1" role="dialog" aria-labelledby="cartModalLabel" aria-hidden="true">
<div class="modal-dialog modal-cart modal-dialog-cart">
<div class="modal-content modal-cart modal-content-cart">
<div class="modal-body modal-cart" style="overflow:scroll">
<div class="row hide cart-s1-common" data-step="1" id="modal-step-1">
<div class="row modal-header modal-header-cart" >
<div class="modal-shopping-cart"></div>
</div>
<div class="row cart-s1-title">
<div class="col-xs-5 txt-center">
ORDER
</div>
<div class="col-xs-2 txt-center">
PRICE
</div>
<div class="col-xs-2 txt-center">
QTY
</div>
<div class="col-xs-3 txt-center">
TOTAL
</div>
</div>
<br/>
</div>
<div class="row hide cart-s2-common" data-step="2">
<div class="row cart-s2-title">
<div class="col-xs-12 txt-center">
TIME REMAINING:<br/>
<label id="lblCountDown"></label>
</div>
</div>
<div class="row cart-s2-content">
<div class="col-xs-12 txt-center">
<div class="row">
<input id='cart-s2-timepicker' type='button' class='cart-s2-timepicker' value='10:00'/>
<input id='cart-s2-timepicker' type='button' class='cart-s2-timepicker' value='11:00'/>
<input id='cart-s2-timepicker' type='button' class='cart-s2-timepicker' value='12:00'/>
</div>
<div class="row">
<input id='cart-s2-timepicker' type='button' class='cart-s2-timepicker' value='13:00'/>
<input id='cart-s2-timepicker' type='button' class='cart-s2-timepicker' value='14:00'/>
<input id='cart-s2-timepicker' type='button' class='cart-s2-timepicker' value='15:00'/>
</div>
<div class="row">
<input id='cart-s2-timepicker' type='button' class='cart-s2-timepicker' value='16:00'/>
<input id='cart-s2-timepicker' type='button' class='cart-s2-timepicker' value='17:00'/>
<input id='cart-s2-timepicker' type='button' class='cart-s2-timepicker' value='18:00'/>
</div>
<div class="row">
<input id='cart-s2-timepicker' type='button' class='cart-s2-timepicker' value='19:00'/>
<input id='cart-s2-timepicker' type='button' class='cart-s2-timepicker' value='20:00'/>
<input id='cart-s2-timepicker' type='button' class='cart-s2-timepicker' value='21:00'/>
</div>
</div>
</div>
</div>
<div class="row hide cart-s3-common" data-step="3">
This is the last step!!!
</div>
</div>
<div class="modal-footer modal-footer-cart">
<button type="button" class="btn btn-cart js-btn-step pull-left" data-orientation="cancel" data-dismiss="modal"></button>
<button type="button" class="btn btn-cart js-btn-step" data-orientation="previous"></button>
<button type="button" class="btn btn-cart btn-success js-btn-step" data-orientation="next"></button>
</div>
</div>
</div>
</div>
<script>
$('#cartModal').modalSteps({
btnCancelHtml: 'Quit',
btnPreviousHtml: 'Back',
btnNextHtml: 'Go',
btnLastStepHtml: 'Finish'
});
</script>
</body>
</html>

My suggestion is:
Order your includes in header - jquery, bootstrap css + other css files, bootstrap.js, respond.js then jquery-bootstrap-modal-steps.js (as I see from your code this one is missing) and your specific page scripts. It should look like this.
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1,maximum-scale=1, user-scalable=no">
<title>WhyQ</title>
<link href="http://fonts.googleapis.com/css?family=Titillium+Web:400,400italic,700" rel="stylesheet" type="text/css">
<link href="//maxcdn.bootstrapcdn.com/font-awesome/4.2.0/css/font-awesome.min.css" rel="stylesheet">
<link rel="stylesheet" type="text/css" href="css/bootstrap.min.css">
<link rel="stylesheet" type="text/css" href="css/style.css">
<link rel="stylesheet" type="text/css" href="css/style-o.css">
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script>
<script type="text/javascript" src="js/bootstrap.min.js"></script>
<script type="text/javascript" src="js/respond.min.js"></script>
<script type="text/javascript" src="js/jquery-bootstrap-modal-steps.js"></script>
<script type="text/javascript" src="js/scripts.js"></script>
</head>
You can use only $('#myModal').modalSteps(); and test if it works correctly then start adding Available options and callbacks.
for more info check this =>
http://www.jqueryscript.net/other/Create-Step-By-Step-Modal-with-jQuery-Bootstrap.html

Related

Modal Bootstrap with application Spring boot (JAVA)

I'm a beginner and I'm trying to add a Javascript event to the delete button so that a modal appears for application with Spring Boot Java.
I'm not sure if my bootstrap connection is done correctly.
I have a LayoutDefault where I call the other layers. In LayoutDefault I'm adding the links for bootstrap connection.
Can anyone help me trigger the event?
modal's html:
<!DOCTYPE html>
<html xmlns="http://wwww.w3.org/1999/xhtml"
xmlns:th="http://www.thymeleaf.org"
xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout">
<div class="modal" id ="confirmationExclusion" tabindex="-1" data-backdrop="static">
<div class="modal-dialog">
<form action="/title" method="post">
<input type="hidden" name="_method" value="DELETE"/>
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title">You have sure?</h5>
<button type="button" class="close-close" data-bs-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
</div>
<div class="modal-body">
<span></span>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">cancel</button>
<button type="button" class="btn btn-primary">delete</button>
</div>
</div>
</form>
</div>
</div>
</html>
button to activate modal:
<!DOCTYPE>
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:th="http://www.thymeleaf.org"
xmlns:layout="http://ultraq.net.nz/thymeleaf/layout"
layout:decorate="~{LayoutDefault}"
>
<head>
<meta charset="UTF-8">
<title>Pesquisa</title>
</head>
<body>
<section layout:fragment="content">
....
<button type="button" data-toggle="modal" data-target="#deleteModal" th:attr="data-codigo=${titulo.codigo}, data-descricao=${title.describle}"
class="btn btn-link" title="Delete">
<i class="material-icons">delete</i>
</button>
<script src="/js/cob.js"></script>
....
</section
</body>
</html>
my file js for trigger the event cob.js
$('#deleteModal').on('show.bs.modal', function(event){
var button = $(event.relatedTarget);
var codTitle = button.data('cod');
var describleTitle = button.data('describle');
var modal = $(this);
var form = modal.find('form');
var action = form.data('url-base');
if(!action.endsWith('/')){
action += '/';
}
form.attr('action', action + codTitle);
modal.find('.modal-body span').html('Are you sure you want to delete the record <strong>'+describleTitle+'<strong>');
});
LayoutDefault:
<!DOCTYPE>
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:th="http://www.thymeleaf.org"
xmlns:layout="http://ultraq.net.nz/thymeleaf/layout"
>
<head>
<link rel="stylesheet" type="text/css" href="/css/bootstrap.min.css"/>
<meta name="viewport" content="width=device-width, initial-scale=1">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js" type="text/javascript"></script>
<link rel="stylesheet" href= "https://stackpath.bootstrapcdn.com/bootstrap/5.0.0-alpha1/css/bootstrap.min.css" integrity="sha384-r4NyP46KrjDleawBgD5tp8Y7UzmLA05oM1iAEQ17CSuDqnUK2+k9luXQOfXJCJ4I"
crossorigin="anonymous" />
<script src="https://cdn.jsdelivr.net/npm/popper.js#1.16.0/dist/umd/popper.min.js" integrity="sha384-Q6E9RHvbIyZFJoft+2mJbHaEWldlvI9IOYy5n3zV9zzTtmI3UksdQRVvoxMfooAo"
crossorigin="anonymous"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/5.0.0-alpha1/js/bootstrap.min.js" integrity="sha384-oesi62hOLfzrys4LxRF63OJCXdXDipiYWBnvTl9Y9/TRlw5xlKIEHpNyvvDShgf/"
crossorigin="anonymous"></script>
<link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet"/>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
<header th:replace = "Header"></header>
<section layout:fragment="content">
<p> Main content </p>
</section>
<!--
not found
<script src="/js/popper.min.js"></script>
<script src="/js/jquery-3.6.0.min.js"></script>
<script src="/js/bootstrap.min.js"></script>
-->
</body>
</html>
<script src="/js/popper.min.js"></script>
<script src="/js/jquery-3.6.0.min.js"></script>
<script src="/js/bootstrap.min.js"></script>
there is a path problem in the src of the javascript change to
<script th:src="#{/js/popper.min.js}"></script>
<script th:src="#{/js/jquery-3.6.0.min.js}"></script>
<script th:src="#{/js/bootstrap.min.js}"></script>

how to call bootstrap5 modals using vanilla javascript?

there is a button
<button onclick="showModal('#Url.Action("EditUserProfile","Profile",null,Context.Request.Scheme)','ویرایش پروفایل کاربر');"
class="btn btn-warning w-100 mb-3">
ویرایش اطلاعات
</button>
there is a modal
<div class="modal fade" id="modal" tabindex="-1" aria-labelledby="exampleModalLabel" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="modal-title"></h5>
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
</div>
<div id="modal-body" class="modal-body">
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Close</button>
<button type="button" class="btn btn-primary">Save changes</button>
</div>
</div>
</div>
</div>
when I click the button I want show modal only using vanilla JavaScript
async function showModal(url, title) {
let modalEl = document.querySelector('#modal');
let bsModal = Bootstrap.Modal.getInstance(modalEl);
let modalTitle = document.querySelector('#modal-title');
let modalBody = document.querySelector('#modal-body');
let requestPage = await fetch(url);
let requestPageResponse = await requestPage.text();
modalTitle.innerHTML = title;
modalBody.innerHTML = requestPageResponse;
bsModal.show();
}
when I try this I get this error
Uncaught (in promise) ReferenceError: Bootstrap is not defined
at showModal
<!DOCTYPE html>
<html lang="fa-IR" dir="rtl">
<head>
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta charset="utf-8" />
<title>#ViewBag.Title</title>
<script src="https://kit.fontawesome.com/0842d2bf89.js" crossorigin="anonymous"></script>
<link href="~/Bootstrap/bootstrap.css" rel="stylesheet" />
<link href="~/css/main.css" rel="stylesheet" />
</head>
<body>
<div class="main-wraper">
<vc:top-nav></vc:top-nav>
<div class="main-content">
#RenderBody()
</div>
<vc:footer></vc:footer>
</div>
<script src="~/Bootstrap/bootstrap.min.js"></script>
<script src="~/js/navbar.js"></script>
#RenderSection("scripts", false)
</body>
</html>
You need to make sure the twitter-bootstrap script is above your showModal() function
Something like:
<html>
<head>
<!-- Required meta tags -->
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<!-- Bootstrap CSS -->
<link href="https://cdn.jsdelivr.net/npm/bootstrap#5.0.0-beta2/dist/css/bootstrap.min.css" rel="stylesheet"
integrity="sha384-BmbxuPwQa2lc/FVzBcNJ7UAyJxM6wuqIj61tLrc4wSX0szH/Ev+nYRRuWlolflfl" crossorigin="anonymous">
<title>Hello, world!</title>
</head>
<body>
<h1>Hello, world!</h1>
<!-- This script must be above -->
<script src="https://cdn.jsdelivr.net/npm/bootstrap#5.0.0-beta2/dist/js/bootstrap.bundle.min.js"
integrity="sha384-b5kHyXgcpbZJO/tY9Ul7kGkf1S0CWuKcCD38l8YkeH8z8QjE0GmW1gYU5S9FOnJ0"
crossorigin="anonymous"></script>
<!-- This script must be below your boostrap script -->
<script src="YOUR SHOW MODAL ASYNC FILE PATH"></script>
</body>
</html>
In your showModal function
Change this line
let bsModal = Bootstrap.Modal.getInstance(modalEl);
to this
let bsModal = new boostrap.Modal(modalEl)
See docs

Bootstrap Modal is not executing properly

I am trying to implement bootstrap login Modal functionality in my code, but the output is not showing screen is not showing it.
Here is the output to the screen
The red box in the image is where I want my Login Modal to be shown.
I have tried using the inspect element, to check the issue with my code, but it is also not displaying it.
But it is showing this error
popper.min.js:4 Uncaught SyntaxError: Unexpected token 'export'
Header files attached:
<head>
<!-- Required meta tags always come first -->
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<meta http-equiv="x-ua-compatible" content="ie=edge">
<!-- Scripts -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.15.0/popper.min.js"></script>
<script src="https://kit.fontawesome.com/4ccd9cbb4a.js" crossorigin="anonymous"></script>
<!-- Bootstrap CSS -->
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
<link type="text/css" rel="stylesheet" href="./node_modules/bootstrap/dist/css/bootstrap.min.css">
<link href="css/styles.css" rel="stylesheet">
<title>Ristorante Con Fusion</title>
</head>
Login Modal Code:
<div id="loginModal" class="modal fade" role="dialog">
<div class="modal-dialog modal-lg" role="content">
<!-- Modal content-->
<div class="modal-content">
<div class="modal-header">
<h4 class="modal-title">Login </h4>
<button type="button" class="close" data-dismiss="modal">×</button>
</div>
<div class="modal-body">
<form>
<div class="form-row">
<div class="form-group col-sm-4">
<label class="sr-only" for="exampleInputEmail3">Email address</label>
<input type="email" class="form-control form-control-sm mr-1" id="exampleInputEmail3" placeholder="Enter email">
</div>
<div class="form-group col-sm-4">
<label class="sr-only" for="exampleInputPassword3">Password</label>
<input type="password" class="form-control form-control-sm mr-1" id="exampleInputPassword3" placeholder="Password">
</div>
<div class="col-sm-auto">
<div class="form-check">
<input class="form-check-input" type="checkbox">
<label class="form-check-label"> Remember me
</label>
</div>
</div>
</div>
<div class="form-row">
<button type="button" class="btn btn-secondary btn-sm ml-auto" data-dismiss="modal">Cancel</button>
<button type="submit" class="btn btn-primary btn-sm ml-1">Sign in</button>
</div>
</form>
</div>
</div>
</div>
</div>
Use the getbootstap link for popper js instead of cdn link
<script src="https://getbootstrap.com/docs/4.1/assets/js/vendor/popper.min.js
"></script>

display alert after button is clicked

I have a button that pops up an alert "Hello" after being clicked.
It works fine for the first click but after I close the alert and I clicked the button again, the alert doesn't shows. Please help.
<!DOCTYPE html>
<html>
<head>
<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.1.1/jquery.min.js"></script>
<script
src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<style>
.hidden {
display: none;
}
</style>
<title>Show Alert</title>
</head>
<body id="page-top" data-spy="scroll" data-target=".navbar-fixed-top">
<div class="container">
<div class="row">
<div class="alert alert-success hidden" id="success-alert">
<button type="button" class="close" data-dismiss="alert">x</button>
<span class="glyphicon glyphicon-ok"></span> Hello
</div>
</div>
<div class="row">
<button id="btn" type="button" class="btn btn-default">Open
Alert</button>
</div>
</div>
<script type="text/javascript">
$(document).ready(function() {
$("#btn").click(function() {
$('#success-alert').removeClass('hidden');
});
});
</script>
</body>
</html>
Your hidden class should come back but is not due to data-dismiss. Remove data-dismiss from your closing button and attach a click event to it which will give back the hidden class on click. Here's the working code.
<!DOCTYPE html>
<html>
<head>
<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.1.1/jquery.min.js"></script>
<script
src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<style>
.hidden {
display: none;
}
</style>
<title>Show Alert</title>
</head>
<body id="page-top" data-spy="scroll" data-target=".navbar-fixed-top">
<div class="container">
<div class="row">
<div class="alert alert-success hidden" id="success-alert">
<button type="button" class="close">x</button>
<span class="glyphicon glyphicon-ok"></span> Hello
</div>
</div>
<div class="row">
<button id="btn" type="button" class="btn btn-default">Open
Alert</button>
</div>
</div>
<script type="text/javascript">
$(document).ready(function() {
$("#btn").click(function() {
$('#success-alert').removeClass('hidden');
});
$("button.close").click(function() {
$('#success-alert').addClass('hidden');
});
});
</script>
</body>
</html>
This is because
Data-dismiss completely removes the element. Remove this attribute and bind the click event on close button, You can hide the alert using this event.
<!DOCTYPE html>
<html>
<head>
<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.1.1/jquery.min.js"></script>
<script
src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<style>
.hidden {
display: none;
}
</style>
<title>Show Alert</title>
</head>
<body id="page-top" data-spy="scroll" data-target=".navbar-fixed-top">
<div class="container">
<div class="row">
<div class="alert alert-success hidden" id="success-alert">
<button type="button" class="close" >x</button>
<span class="glyphicon glyphicon-ok"></span> Hello
</div>
</div>
<div class="row">
<button id="btn" type="button" class="btn btn-default">Open
Alert</button>
</div>
</div>
<script type="text/javascript">
$(document).ready(function() {
$("#btn").click(function() {
$('#success-alert').removeClass('hidden');
});
$(".close").click(function() {
$("#success-alert").addClass('hidden');
});
});
</script>
</body>
</html>

How to hide an element within modal fade

I want to hide the text "Enter Password" and the blank box first and show when I click the radio "Private". My code is following. However, it does not work since when I click the "create a new room", the "Enter Password" has already showed in the modal content, and nothing happened when I click Private. How can I fix my code? Thank you so much!
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Create Role</title>
<!-- Latest compiled and minified CSS -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
<script>
$(document).ready(function(){
$("#pwd, #pwdblank").hide();
$("#inlineRadio2").click(function(){
$("#pwd, #pwdblank").show(500);
});
});
</script>
</head>
<body>
<nav class="navbar navbar-default">
<div class="container">
<ul class="nav navbar-nav">
<li class="active">Rooms</li>
<li><a data-toggle="modal" data-target="#createRoomModal">Create New Room</a></li>
</ul>
<ul class="nav navbar-nav navbar-right">
<li><span class="glyphicon glyphicon-log-in"></span> Logout</li>
</ul>
</div>
</nav>
<div class="container">
<div class="row">
</div>
</div>
<div id="createRoomModal" 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">Create a new room</h4>
</div>
<div class="modal-body">
<form id="form_room" method="post" action="/create-room">
<fieldset class="form-group">
<label class="form-check-inline">
<input class="form-check-input" type="radio" name="room_type" id="inlineRadio1" value="public"> Public
</label>
<label class="form-check-inline">
<input class="form-check-input" type="radio" name="room_type" id="inlineRadio2" value="private"> Private
</label>
<label class="form-check-inline">
<p id="pwd">Enter password</p>
<input class="form-check-input" type="text" name="text" id="pwdblank">
</label>
</fieldset>
</form>
</div>
<div class="modal-footer">
<button type="submit" class="btn btn-success" form="form_room">Create</button>
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
<script src="script-index.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js" integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa" crossorigin="anonymous"></script>
</body>
Hello See The Below One Hope you are looking for this...
$(document).ready(function(){
$("#pwd, #pwdblank").hide();
$("#inlineRadio2").click(function(){
$("#pwd, #pwdblank").show(500);
});
$("#inlineRadio1").click(function(){
$("#pwd, #pwdblank").hide(500);
});
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
<script src="script-index.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js" integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa" crossorigin="anonymous"></script>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Create Role</title>
<!-- Latest compiled and minified CSS -->
</head>
<body>
<nav class="navbar navbar-default">
<div class="container">
<ul class="nav navbar-nav">
<li class="active">Rooms</li>
<li><a data-toggle="modal" data-target="#createRoomModal">Create New Room</a></li>
</ul>
<ul class="nav navbar-nav navbar-right">
<li><span class="glyphicon glyphicon-log-in"></span> Logout</li>
</ul>
</div>
</nav>
<div class="container">
<div class="row">
</div>
</div>
<div id="createRoomModal" 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">Create a new room</h4>
</div>
<div class="modal-body">
<form id="form_room" method="post" action="/create-room">
<fieldset class="form-group">
<label class="form-check-inline">
<input class="form-check-input" type="radio" name="room_type" id="inlineRadio1" value="public"> Public
</label>
<label class="form-check-inline">
<input class="form-check-input" type="radio" name="room_type" id="inlineRadio2" value="private"> Private
</label>
<label class="form-check-inline">
<p id="pwd">Enter password</p>
<input class="form-check-input" type="text" name="text" id="pwdblank">
</label>
</fieldset>
</form>
</div>
<div class="modal-footer">
<button type="submit" class="btn btn-success" form="form_room">Create</button>
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
</body>
</html>
Use show.bs.modal event as follows
$('#myModal').on('show.bs.modal', function (e) {
// do something...
// this code runs just before the modal is shown
// hide your field here
});
Use documentation reference here

Categories