Archivo 1: nuevoPedido.php
Funciones implementadas en JavaScript:
Código:
Parte donde se invocan del fichero: function objetoAjax(){
var xmlhttp=false;
try {
xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
try {
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
} catch (E) {
xmlhttp = false;
}
}
if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
xmlhttp = new XMLHttpRequest();
}
return xmlhttp;
}
function comprobarFestivo(){
divResultado = document.getElementById('festivo');
ajax=objetoAjax();
if (document.getElementById('dia').value!='' && document.getElementById('mes')!='' && document.getElementById('year')!='')
{
//Si la fecha está completa analizamos el ámbito de ejecucion de la consulta.
if (document.getElementById('nacional').checked==true)
$ambitoSeleccionado = 'nacional';
else if(document.getElementById('selectComunidades').value!='')
$ambitoSeleccionado = document.getElementById('selectComunidades').value;
else if(document.getElementById('selectProvincias').value!=''){
$ambitoSeleccionado = calcularComunidad(document.getElementById('selectProvincias').value);
}
$dia = document.getElementById('dia');
$mes = document.getElementById('mes');
}
ajax.open('GET', 'nuevoPedido2.php?ambitoSeleccionado='+ambitoSeleccionado+'&dia='+dia+'&mes='+mes);
ajax.onreadystatechange=function() {
if (ajax.readyState==4) {
divResultado.innerHTML = ajax.responseText;
}
}
ajax.send(null)
}
Código HTML:
<div class="ejemplo"> <div> <p> <span class="grupo"> <label for="dia"> <input name="dia" type="text" class="fechaA day post rang10" id="dia" value="" size="4" maxlength="2" onchange="comprobarFestivo()"/> </label> <label for="mes"> <input class="fechaA month" maxlength="2" type="text" id="mes" name="mes" value="" size="4" onchange="comprobarFestivo()"/> </label> - <label for="year"> <input class="fechaA year" maxlength="4" type="text" id="year" name="year" value="" size="8" onchange="comprobarFestivo()"/> </label> </span></p> </div> </div> <div id="festivo"></div>
Código PHP:
// Anteriormente cargo los datos de la base de datos.
if(isset($_GET['ambitoSeleccionado'] and $_GET['dia'] and $_GET['mes'])){
$ambito=$_GET['ambitoSeleccionado'];
$dia=$_GET['dia'];
$mes=$_GET['mes'];
}
$sql=mysql_query("SELECT dia
FROM festivos
WHERE dia='$dia' AND mes='$mes'",$con);
if(mysql_num_rows($sql)!=0){
if($ambito != 'nacional'){
$row = mysql_fetch_array($sql);
if ($row['$ambito']==1){
echo "</p>El día elegido es festivo, esta circunstancia puede hacer que se <b>incremente el precio</b> </p>";
}else{
echo "El día elegido no presenta festividad alguna";
}
}else{
echo "</p>El día elegido es festivo, esta circunstancia puede hacer que se <b>incremente el precio</b> </p>";
}
}

