Good morning everyone, I'm making a website that uses JQuery and Bootstrap (including some plugins like DateTimePicker). More or less I get it to work but I can not make it clear to me the subject of the loads of the different scripts and styles. For example, I have the following home page, a form that validates if a user exists:
<html>
<head>
<title></title>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script src='js_propio/cookies.js'></script>
<script src='js_propio/funciones.js'></script>
<script src='js_propio/eventos.js'></script>
<!-- -->
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" type="text/css" href="assets/css/vendor.css">
<link rel="stylesheet" type="text/css" href="assets/css/flat-admin.css">
<!-- Theme -->
<link rel="stylesheet" type="text/css" href="assets/css/theme/blue-sky.css">
<link rel="stylesheet" type="text/css" href="assets/css/theme/blue.css">
<link rel="stylesheet" type="text/css" href="assets/css/theme/red.css">
<link rel="stylesheet" type="text/css" href="assets/css/theme/yellow.css">
</head>
<body>
<!-- AQUI VA EL CONTENIDO -->
<script type="text/javascript" src="assets/js/vendor.js"></script>
<script type="text/javascript" src="assets/js/app.js"></script>
<script src='js_propio/cookies.js'></script>
</body>
</html>
For the functions that I have programmed, I carry out the loads of the other pages with a GET method, which cleans a certain DIV and loads inside the html.
Here is an example of the function:
$('body').on('click', "#btnCita", function(ev){
$.get( "form.html", function( data ) {
$("#carga").html('');
$("#carga").html(data);
selecEspecialidad();
});
});
The problem that arises is that, if I leave the calls to scripts that are in your head (the same as those in the head of the main page) many times the functions are executed twice, instead, if I delete them and leave html only, trying to make use of the scripts that are on the main page, they do not run.
Likewise, in another of the charges, I call a page with a form, in which one of the fields is a calendar (in Spanish).
The problem here lies in that, the calendar configuration is found within a $ (document) .ready (function ()), so it does not it executes correctly when executed when loading the page, and not at be loaded on the main page (I do not know if I explained myself well)
(EDITION: this last paragraph I can not edit it to improve the writing because the idea is not understood).
<div class="row" id="datosCita">
<div class="col-md-12">
<div class="card">
<div class="card-header oculto">
Rellene los siguientes datos
</div>
<div class="card-body">
<div class="row">
<div id="datos" class="oculto">
<select class="select2" id="listEspec">
<option value="0">-- Seleccione una especialidad --</option>
</select>
</div>
<div id="profesionales" class="oculto">
<select class="select2" id="listProf">
<option value="0">-- Seleccione un profesional --</option>
</select>
</div>
<div class="input-group oculto">
<div class="input-group-addon">
<i class="fa fa-calendar"></i>
</div>
<input class="form-control" id="date" name="date" placeholder="DD/MM/YYYY" type="text"/>
</div>
</div>
<div id="cargaTablaCitas"></div>
<div id="iconosNav">
<img src="iconos/siguiente.png" id="btnSiguiente" style="cursor: pointer;"/>
</div>
</div>
</div>
</div>
</div>
</div>
<div class="col-md-12">
<div class="form-footer">
<div class="form-group">
<div class="col-md-9 col-md-offset-3">
<button type="submit" class="btn btn-primary">Confirmar cita</button>
<button type="button" class="btn btn-default">Cancelar</button>
</div>
</div>
</div>
</form>
</div>
</div>
</div>
</div>
</div>
</div>
<script type="text/javascript" src="assets/js/vendor.js"></script>
<script type="text/javascript" src="assets/js/app.js"></script>
<script src='js_propio/cookies.js'></script>
<!-- Include Date Range Picker -->
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-datepicker/1.4.1/js/bootstrap-datepicker.min.js"></script>
<script src="js/moment.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-datepicker/1.4.1/locales/bootstrap-datepicker.es.min.js"></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-datepicker/1.4.1/css/bootstrap-datepicker3.css"/>
<script type="text/javascript">
$(document).ready(function(){
var date_input=$('input[name="date"]'); //our date input has the name "date"
var container=$('.bootstrap-iso form').length>0 ? $('.bootstrap-iso form').parent() : "body";
date_input.datepicker({
useCurrent: false,
format: 'dd/mm/yyyy',
container: container,
todayHighlight: true,
autoclose: true,
startDate: "today",
language: 'es'
}).on('closeUp',function(){
var marca = true;
if(marca == true){
alert($(this).val());
}
//alert('a');
})
})
</script>
<script src='js_propio/eventos.js'></script>
As I said before, I can make it work but changing the order of the script in a crazy way.