RSS
Recortes: 26
html
Ajax
XMLHttpRequest
imagenes
JS
css
cuentas_bancarias
trim
nie
eventos
cif
variable
scroll
declarada
altura
vacio
php
forma
correo
xhtml
temporizado
jquery
div
button
validaciones
radio
head
CSharp
texto
dni
cadena
validacion_fecha
redireccion
historia
tiempo
mayusculas
electronico
checkbox
validar
redirecicon
function isDefined(sVarName) { return (typeof(window[sVarName]) == "undefined") ? false : true; }
var pagina = 'http://www.tiexo.com'; var segundos = 5; function redireccion() { document.location.href=pagina; } setTimeout("redireccion()",segundos);Oh! y juanjo me dice que tambien se hace de esta forma, creo que es mas optimo!
<META HTTP-EQUIV="Refresh" CONTENT="5; URL=http://www.tiexo.com">Gracias Juanjo
function validate(nombreForma) { var theMessage = "Please complete the following:\n-----------------------------------\n"; var noErrors = theMessage // No vacio if (document.nombreForma.name.value=="") { theMessage = theMessage + "\n --> Your name"; } // Validar un correo electronico if (!/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,4})+$/.test(document.form1.email.value)){ theMessage = theMessage + "\n --> Enter a valid e-mail address"; } // Entrada de cierta cantidad de letras var lengthCheck = document.nombreForma.code.value if (lengthCheck.length < 4) { theMessage = theMessage + "\n --> Enter 4 character code"; } // radio button seleccionado var radioCheck = false; for (i = 0; i < document.nombreForma.gender.length; i++) { if (document.nombreForma.gender[i].checked) radioCheck = true; } if (!radioCheck) { theMessage = theMessage + "\n --> Choose your gender"; } // Al menos un check box var multiCheckbox = false; for (i = 0; i < document.nombreForma.session.length; i++) { if (document.nombreForma.session[i].checked) multiCheckbox = true; } if (!multiCheckbox) { theMessage = theMessage + "\n --> Choose which session(s)"; } // Select List Usar var listCheck = document.form1.location.selectedIndex; if (document.nombreForma.location.options[listCheck].value=="none") { theMessage = theMessage + "\n --> Choose a location"; } // Checkbox Activado var boxCheck = false; if (document.nombreForma.confirm.checked) { boxCheck = true; } if (!boxCheck) { theMessage = theMessage + "\n --> Agree to the terms"; } // No hubo errores if (theMessage == noErrors) { return true; } else { // Errores encontrados alert(theMessage); return false; } }
function setActiveStyleSheet(title) { var i, a, main; for(i=0; (a = document.getElementsByTagName("link")[i]); i++) { if(a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title")) { a.disabled = true; if(a.getAttribute("title") == title) a.disabled = false; } } } function getActiveStyleSheet() { var i, a; for(i=0; (a = document.getElementsByTagName("link")[i]); i++) { if(a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title") && !a.disabled) return a.getAttribute("title"); } return null; } function getPreferredStyleSheet() { var i, a; for(i=0; (a = document.getElementsByTagName("link")[i]); i++) { if(a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("rel").indexOf("alt") == -1 && a.getAttribute("title") ) return a.getAttribute("title"); } return null; } function createCookie(name,value,days) { if (days) { var date = new Date(); date.setTime(date.getTime()+(days*24*60*60*1000)); var expires = "; expires="+date.toGMTString(); } else expires = ""; document.cookie = name+"="+value+expires+"; path=/"; } function readCookie(name) { var nameEQ = name + "="; var ca = document.cookie.split(';'); for(var i=0;i < ca.length;i++) { var c = ca[i]; while (c.charAt(0)==' ') c = c.substring(1,c.length); if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length); } return null; } function leerEstilo() { var cookie = readCookie("style"); var title; if(cookie == null){ title = "verde"; } else { title = cookie ? cookie : getPreferredStyleSheet(); } setActiveStyleSheet(title); } function guardarEstilo() { var title = getActiveStyleSheet(); createCookie("style", title, 365); }En el head de nuestro HTML escribimos las siguientes sentencias para utilizar dicho javascript y nuestros css:
<!-- declaración de estilos css --> <link rel="stylesheet" type="text/css" href="estilos/verde.css" title="verde"> <link rel="alternate stylesheet" type="text/css" href="estilos/azul.css" title="azul"> <link rel="alternate stylesheet" type="text/css" href="estilos/rojo.css" title="rojo"> <link rel="alternate stylesheet" type="text/css" href="estilos/amarillo.css" title="amarillo"> <link rel="alternate stylesheet" type="text/css" href="estilos/gris.css" title="gris"> <link rel="alternate stylesheet" type="text/css" href="estilos/marron.css" title="marron"> <link rel="alternate stylesheet" type="text/css" href="estilos/lila.css" title="lila"> <link rel="alternate stylesheet" type="text/css" href="estilos/naranja.css" title="naranja"> <!-- fin declaración estilos css --> <!-- declaración de ficheros javascript --> <script type="text/javascript" src="javascript/styleswitcher.js"></script> <!-- fin declaración de ficheros javascript -->Con el atributo rel="stylesheet" indicamos cual es el estilo por defecto y con rel="alternate stylesheet" cuales son los estilos alternativos. Hay que añadir un title para identificar el estilo y poder guardarlo en la cookie.
<table class="tabla2" cellspacing=0 cellpadding=0 width=136 border=0> <tbody> <tr> <td valign=top class="color00f" align=middle> <a href="#" onclick="setActiveStyleSheet('verde', 1); return false; actualizar();" style="text-decoration: none"> <img src="imagenes/estilos/verde.jpg" width=26px height=26px alt="verde" title="verde"></a> </td> <td valign=top class="color00f" align=middle> <a href="#" onclick="setActiveStyleSheet('rojo', 1); return false; actualizar();" style="text-decoration: none"> <img src="imagenes/estilos/rojo.jpg" width=26px height=26px alt="rojo" title="rojo"></a> </td> <td valign=top class="color00f" align=middle> <a href="#" onclick="setActiveStyleSheet('azul', 1); return false; actualizar();" style="text-decoration: none"> <img src="imagenes/estilos/azul.jpg" width=26px height=26px alt="azul" title="azul"></a> </td> <td valign=top class="color00f" align=middle> <a href="#" onclick="setActiveStyleSheet('marron', 1); return false; actualizar();" style="text-decoration: none"> <img src="imagenes/estilos/marron.jpg" width=26px height=26px alt="marron" title="marron"></a> </td> </tr> <tr> <td valign=top class="color00f" align=middle> <a href="#" onclick="setActiveStyleSheet('lila', 1); return false; actualizar();" style="text-decoration: none"> <img src="imagenes/estilos/lila.jpg" width=26px height=26px alt="lila" title="lila"></a> </td> <td valign=top class="color00f" align=middle> <a href="#" onclick="setActiveStyleSheet('naranja', 1); return false; actualizar();" style="text-decoration: none"> <img src="imagenes/estilos/naranja.jpg" width=26px height=26px alt="naranja" title="naranja"></a> </td> <td valign=top class="color00f" align=middle> <a href="#" onclick="setActiveStyleSheet('amarillo', 1); return false; actualizar();" style="text-decoration: none"> <img src="imagenes/estilos/amarillo.jpg" width=26px height=26px alt="amarillo" title="amarillo"></a> </td> <td valign=top class="color00f" align=middle> <a href="#" onclick="setActiveStyleSheet('gris', 1); return false; actualizar();" style="text-decoration: none"> <img src="imagenes/estilos/gris.jpg" width=26px height=26px alt="gris" title="gris"></a> </td> </tr> </tbody> </table>Al hacer click sobre la imagen se llama a la función javascript setActiveStyleSheet(estilo, 1); que activa dicho estilo y con la función actualizar(); se actualiza la página para mostrarla con el nuevo estilo.
<body onLoad="leerEstilo();" onunload="guardarEstilo();">Estas llamadas en el body hacen que cuando se cargue la página se lea la cookie y se active el estilo que contiene dicha cookie y que al cerrar la página se lea el estilo y se guarde en una cookie.
function Fadomatic (element, rate, initialOpacity, minOpacity, maxOpacity)Donde:element - Es el elemento con el que vamos a jugar rate- La velocidad (de 0 a 100)initialOpacity (opcional, predeterminado 100) - La opacidad de inicio del elemento (de 0 a 100)minOpacity (opcional, predeterminado 0) - La opacidad minima del elemento (de 0 a 100)maxOpacity (opcional, predeterminado 0) - La opacidad máxima del elemento (de 0 a 100)
// Fade interval in milliseconds // Make this larger if you experience performance issues Fadomatic.INTERVAL_MILLIS = 50; // Creates a fader // element - The element to fade // speed - The speed to fade at, from 0.0 to 100.0 // initialOpacity (optional, default 100) - element's starting opacity, 0 to 100 // minOpacity (optional, default 0) - element's minimum opacity, 0 to 100 // maxOpacity (optional, default 0) - element's minimum opacity, 0 to 100 function Fadomatic (element, rate, initialOpacity, minOpacity, maxOpacity) { this._element = element; this._intervalId = null; this._rate = rate; this._isFadeOut = true; // Set initial opacity and bounds // NB use 99 instead of 100 to avoid flicker at start of fade this._minOpacity = 0; this._maxOpacity = 99; this._opacity = 99; if (typeof minOpacity != 'undefined') { if (minOpacity < 0) { this._minOpacity = 0; } else if (minOpacity > 99) { this._minOpacity = 99; } else { this._minOpacity = minOpacity; } } if (typeof maxOpacity != 'undefined') { if (maxOpacity < 0) { this._maxOpacity = 0; } else if (maxOpacity > 99) { this._maxOpacity = 99; } else { this._maxOpacity = maxOpacity; } if (this._maxOpacity < this._minOpacity) { this._maxOpacity = this._minOpacity; } } if (typeof initialOpacity != 'undefined') { if (initialOpacity > this._maxOpacity) { this._opacity = this._maxOpacity; } else if (initialOpacity < this._minOpacity) { this._opacity = this._minOpacity; } else { this._opacity = initialOpacity; } } // See if we're using W3C opacity, MSIE filter, or just // toggling visiblity if(typeof element.style.opacity != 'undefined') { this._updateOpacity = this._updateOpacityW3c; } else if(typeof element.style.filter != 'undefined') { // If there's not an alpha filter on the element already, // add one if (element.style.filter.indexOf("alpha") == -1) { // Attempt to preserve existing filters var existingFilters=""; if (element.style.filter) { existingFilters = element.style.filter+" "; } element.style.filter = existingFilters+"alpha(opacity="+this._opacity+")"; } this._updateOpacity = this._updateOpacityMSIE; } else { this._updateOpacity = this._updateVisibility; } this._updateOpacity(); } // Initiates a fade out Fadomatic.prototype.fadeOut = function () { this._isFadeOut = true; this._beginFade(); } // Initiates a fade in Fadomatic.prototype.fadeIn = function () { this._isFadeOut = false; this._beginFade(); } // Makes the element completely opaque, stops any fade in progress Fadomatic.prototype.show = function () { this.haltFade(); this._opacity = this._maxOpacity; this._updateOpacity(); } // Makes the element completely transparent, stops any fade in progress Fadomatic.prototype.hide = function () { this.haltFade(); this._opacity = 0; this._updateOpacity(); } // Halts any fade in progress Fadomatic.prototype.haltFade = function () { clearInterval(this._intervalId); } // Resumes a fade where it was halted Fadomatic.prototype.resumeFade = function () { this._beginFade(); } // Pseudo-private members Fadomatic.prototype._beginFade = function () { this.haltFade(); var objref = this; this._intervalId = setInterval(function() { objref._tickFade(); },Fadomatic.INTERVAL_MILLIS); } Fadomatic.prototype._tickFade = function () { if (this._isFadeOut) { this._opacity -= this._rate; if (this._opacity < this._minOpacity) { this._opacity = this._minOpacity; this.haltFade(); } } else { this._opacity += this._rate; if (this._opacity > this._maxOpacity ) { this._opacity = this._maxOpacity; this.haltFade(); } } this._updateOpacity(); } Fadomatic.prototype._updateVisibility = function () { if (this._opacity > 0) { this._element.style.visibility = 'visible'; } else { this._element.style.visibility = 'hidden'; } } Fadomatic.prototype._updateOpacityW3c = function () { this._element.style.opacity = this._opacity/100; this._updateVisibility(); } Fadomatic.prototype._updateOpacityMSIE = function () { this._element.filters.alpha.opacity = this._opacity; this._updateVisibility(); } Fadomatic.prototype._updateOpacity = null;2.- Incluimos una llamada al script donde lo deseemos utilizar:
<script type="text/javascript" language="JavaScript" src="fadomatic-1_2.js"></script>Incluimos el siguiente CSS:
#caja_fadomatic { width: 150px; height:110px; background-color:#990000; padding:4px; color:#FFFFFF; font:10px Verdana, Arial, Helvetica, sans-serif }Y por último:
<div id="caja_fadomatic"> Caja </div> <p> <a href="javascript:fader.fadeOut();">Ocultar</a> <a href="javascript:fader.fadeIn();">Mostrar</a><br> <br> </p> <script language="javascript"> var fader = new Fadomatic(caja_fadomatic, 5, 100); </script>
String.prototype.removeAccents = function () { var __r = { 'À':'A','�?':'A','Â':'A','Ã':'A','Ä':'A','Å':'A','Æ':'E', 'È':'E','É':'E','Ê':'E','Ë':'E', 'Ì':'I','�?':'I','Î':'I','�?':'I', 'Ò':'O','Ó':'O','Ô':'O','Ö':'O', 'Ù':'U','Ú':'U','Û':'U','Ü':'U', 'Ñ':'N'}; return this.replace(/[À�?ÂÃÄÅÆÈÉÊËÌ�?Î�?ÒÓÔÖÙÚÛÜÑ]/gi, function(m){ var ret = __r[m.toUpperCase()]; if (m === m.toLowerCase()) ret = ret.toLowerCase(); return ret; }); };Uso:
"Perú".removeAccents();
function requerido(campo, id){ if ((campo.value.length==0 || campo.value.length ==undefined) && campo.style.visibility!='hidden') { alert("El campo " + id + " es requerido"); if(campo.type!='hidden' && !campo.disabled){ campo.focus(); } return false; } else { return true; } } function letras (campo, id) { var charpos = campo.value.search("[^A-Za-z]"); if(campo.value.length > 0 && charpos >= 0) { strError = "El campo " + id +" solo permite letras "; alert(strError + "\n [Posicion del caracter erróneo: " + eval(charpos+1)+"]"); campo.focus(); return false; } else {//if return true; } } function numerico(campo, id) { var charpos = campo.value.search("[^0-9]"); if (campo.value.length > 0 && charpos >= 0) { strError = "El campo "+id+" solo acepta digitos "; alert(strError + "\n [El caracter erróneo esta en la posicion: " + eval(charpos+1)+"]"); campo.focus(); return false; } else { return true; } } function alfanumerico(campo, id){ var charpos = campo.value.search("[^A-Za-z0-9., ]"); if(campo.value.length > 0 && charpos >= 0) { strError = "El campo "+id+" solo aceptar letras de A a la Z y digitos"; alert(strError + "\n [Posición del caracter erróneo: " + eval(charpos+1)+"]"); campo.focus(); return false; } else {//if return true; } }Uso: 1. Recomiendo guardar las validaciones en un archivo aparte , por ejemplo validaciones.js
function envia() { var manda = true;//variable que toma el valor de true si cumple la validacion el campo if (numerico(window.document.form.txtCodigo, "Codigo")) { manda = true; } else { manda = false; return false; } if (manda) { window.document.form.accion.value ="Inserta"; //Si los campos cumplen las validaciones window.document.form.submit(); //procedo a insertar el registro en bd }
<script language="javascript" type="text/javascript"> location.href=""; </script>Es sencillo pero muy util
.st { position: relative; /* obligatorio */ width : 160px; /* ajustable */ overflow : hidden; /* obligatorio */ }Código Javascript necesario:
<script type="text/javascript"> window.onload = f_init; var oDiv = null; var hInt = null; var nDir = 0; function f_init() { var nCoordX = 0; var nMaxH = 0; var nlDivs = document.getElementsByTagName("div"); for(i=0; i<nlDivs.length; i++) { var oDiv = nlDivs[i]; if(oDiv.className=="st") { oDiv.onmouseover = f_mover; oDiv.onmousemove = f_mmove; oDiv.onmouseout = f_mout; oDiv.move = f_move; for(ii=0; ii<oDiv.childNodes.length; ii++) { var oImg = nlDivs[i].childNodes[ii]; if(oImg.tagName=="IMG") { oImg.style.position = "absolute"; oImg.style.left = nCoordX+"px"; nCoordX += oImg.width + 5; nMaxH = Math.max(nMaxH, oImg.height); } } oDiv.scrollLeft = 0; oDiv.maxScrollW = oDiv.scrollWidth - oDiv.offsetWidth; oDiv.centerX = (oDiv.offsetWidth / 2); oDiv.style.height = nMaxH+"px"; } } } function f_mover() { if(hInt != null) window.clearInterval(hInt); oDiv = this; hInt = window.setInterval(f_move, 10); } function f_mmove(event) { if(event == null) event = window.event; var x = event.clientX - this.offsetLeft; if(x < this.centerX && this.scrollLeft>0 ) nDir = -1; if(x > this.centerX && this.scrollLeft<this.maxScrollW) nDir = +1; } function f_mout() { window.clearInterval(hInt); hInt = null; oDiv = null; } function f_move() { oDiv.scrollLeft += nDir; }Y código HTML de ejemplo:
<div class="st"> <img src="imagen1.jpg" title="thumb #1" /> <img src="imagen2.jpg" title="thumb #2" /> <img src="imagen3.jpg" title="thumb #3" /> <img src="imagen4.jpg" title="thumb #4" /> </div>
<img class="ic" src="imagenes/imagen1.jpg" srcalt="imagen2.jpg;imagen3.jpg" alt="Pulsa sobre la imágen para cambiarla por otra" />
window.onload = f_init; var isExplorer = (document.all ? true : false); var hFade = null; var imgFade = null; var imgAlfa = 10; function f_init() { var nlImgs = document.getElementsByTagName("img"); for(i=0; i<nlImgs.length; i++) { if(nlImgs[i].className=="ic") { var nSlash = 1 + nlImgs[i].src.lastIndexOf("/"); var sURL = nlImgs[i].src.substr(0, nSlash); nlImgs[i].onclick = f_changeImg; nlImgs[i].step = 0; nlImgs[i].cimg = 0; nlImgs[i].srcalt = nlImgs[i].getAttribute("srcalt").split(";"); for(ii=0; ii<nlImgs[i].srcalt.length; ii++) nlImgs[i].srcalt[ii] = sURL + nlImgs[i].srcalt[ii]; nlImgs[i].srcalt[ii] = nlImgs[i].src; if(isExplorer) nlImgs[i].runtimeStyle.filter = "progid:DXImageTransform.Microsoft.Alpha"; } } } function f_changeImg() { window.clearInterval(hFade); if(this.className=="ic") imgFade = this; switch(imgFade.step) { case 0: imgFade.step = 1; f_startFadeOff(); break; case 1: imgFade.step = 2; f_changeSrc(); break; case 2: imgFade.step = 3; f_startFadeOn(); break; case 3: imgFade.step = 0; imgFade.onclick = f_changeImg; break; } } function f_changeSrc() { imgFade.cimg++; if(imgFade.cimg == imgFade.srcalt.length) imgFade.cimg = 0; imgFade.src = imgFade.srcalt[imgFade.cimg]; f_changeImg(); } function f_startFadeOff() { imgFade.onclick = null; hFade = window.setInterval(f_fadeOff, 100); } function f_fadeOff() { imgAlfa -= 1; imgFade.style.MozOpacity = (imgAlfa/10); if(isExplorer) imgFade.filters.item("DXImageTransform.Microsoft.Alpha").opacity = imgAlfa*10; if(imgAlfa==0) { f_changeImg(); } } function f_startFadeOn() { imgFade.onclick = null; hFade = window.setInterval(f_fadeOn, 100); } function f_fadeOn() { imgAlfa += 1; imgFade.style.MozOpacity = (imgAlfa/10); if(isExplorer) imgFade.filters.item("DXImageTransform.Microsoft.Alpha").opacity = imgAlfa*10; if(imgAlfa==10) { f_changeImg(); } }