Cita:
Otra cosa. Si el javascript de validacion del captcha lo coloco en el head se pierden los numeros aleatorios. me toca dentro del body ¿por que pasa esto? me podrian colaborar por favor. ya he intentado horas y horas y no me da resultado. gracias <script language="javascript" type="text/javascript">
function validarfrm(frm){
if(frm.nombres.value.length < 5){
alert ("Ingrese un Nombre valido");
return false;
}
if(frm.apellidos.value.length < 5){
alert ("El Apellido no es valido");
return false;
}
}
function checkform(theform){
var why = "";
if(theform.txtInput.value == ""){
why += "- Security code should not be empty.\n";
}
if(theform.txtInput.value != ""){
if(ValidCaptcha(theform.txtInput.value) == false){
why += "- Security code did not match.\n";
}
}
if(why != ""){
alert(why);
return false;
}
}
//Generates the captcha function
var a = Math.ceil(Math.random() * 9)+ '';
var b = Math.ceil(Math.random() * 9)+ '';
var c = Math.ceil(Math.random() * 9)+ '';
var d = Math.ceil(Math.random() * 9)+ '';
var e = Math.ceil(Math.random() * 9)+ '';
var code = a + b + c + d + e;
document.getElementById("txtCaptcha").value = code;
document.getElementById("txtCaptchaDiv").innerHTML = code;
// Validate the Entered input aganist the generated security code function
function ValidCaptcha(){
var str1 = removeSpaces(document.getElementById('txtCaptcha') .value);
var str2 = removeSpaces(document.getElementById('txtInput').v alue);
if (str1 == str2){
return true;
}else{
return false;
}
}
// Remove the spaces from the entered and generated code
function removeSpaces(string){
return string.split(' ').join('');
}
</script>
<form name="usuarios" action="usuarios.php" method="post" onSubmit="return validarfrm(this)" onsubmit="return checkform(this);">
// aqui irian los campos a validar normales
// y este es el codigo del campo captcha
<label for="code">Write code below > <span id="txtCaptchaDiv" style="color:#F00"></span><!-- aquí es donde el script se coloque el código generado -->
<input type="hidden" id="txtCaptcha" /></label><!-- aquí es donde el guión colocará una copia del código de validación: es un campo oculto -->
<input type="text" name="txtInput" id="txtInput" size="30" />
</form>
function validarfrm(frm){
if(frm.nombres.value.length < 5){
alert ("Ingrese un Nombre valido");
return false;
}
if(frm.apellidos.value.length < 5){
alert ("El Apellido no es valido");
return false;
}
}
function checkform(theform){
var why = "";
if(theform.txtInput.value == ""){
why += "- Security code should not be empty.\n";
}
if(theform.txtInput.value != ""){
if(ValidCaptcha(theform.txtInput.value) == false){
why += "- Security code did not match.\n";
}
}
if(why != ""){
alert(why);
return false;
}
}
//Generates the captcha function
var a = Math.ceil(Math.random() * 9)+ '';
var b = Math.ceil(Math.random() * 9)+ '';
var c = Math.ceil(Math.random() * 9)+ '';
var d = Math.ceil(Math.random() * 9)+ '';
var e = Math.ceil(Math.random() * 9)+ '';
var code = a + b + c + d + e;
document.getElementById("txtCaptcha").value = code;
document.getElementById("txtCaptchaDiv").innerHTML = code;
// Validate the Entered input aganist the generated security code function
function ValidCaptcha(){
var str1 = removeSpaces(document.getElementById('txtCaptcha') .value);
var str2 = removeSpaces(document.getElementById('txtInput').v alue);
if (str1 == str2){
return true;
}else{
return false;
}
}
// Remove the spaces from the entered and generated code
function removeSpaces(string){
return string.split(' ').join('');
}
</script>
<form name="usuarios" action="usuarios.php" method="post" onSubmit="return validarfrm(this)" onsubmit="return checkform(this);">
// aqui irian los campos a validar normales
// y este es el codigo del campo captcha
<label for="code">Write code below > <span id="txtCaptchaDiv" style="color:#F00"></span><!-- aquí es donde el script se coloque el código generado -->
<input type="hidden" id="txtCaptcha" /></label><!-- aquí es donde el guión colocará una copia del código de validación: es un campo oculto -->
<input type="text" name="txtInput" id="txtInput" size="30" />
</form>