Foros del Web » Programando para Internet » Jquery »

addMethod()

Estas en el tema de addMethod() en el foro de Jquery en Foros del Web. Saludos foro. Intento recibir dos parametros mediante el plugin addMtehod() de Jquery,pero no lo he conseguido, el primer parametro si me lo lee bien, pero ...
  #1 (permalink)  
Antiguo 07/11/2013, 00:48
 
Fecha de Ingreso: enero-2006
Mensajes: 169
Antigüedad: 18 años, 3 meses
Puntos: 0
Pregunta addMethod()

Saludos foro.

Intento recibir dos parametros mediante el plugin addMtehod() de Jquery,pero no lo he conseguido, el primer parametro si me lo lee bien, pero el segundo me dice "Undefined"


El codigo:

Código PHP:
PAGINA "FORM.ASP"
<%@LANGUAGE="VBSCRIPT" CODEPAGE="65001"%>
<!
DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<
html xmlns="http://www.w3.org/1999/xhtml">
<
head>
<
meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<
title>Documento sin título</title>
<
script src="jquery-1.9.0.js"></script>
<script src="jquery.validate.js"></script>
<script src="validate_miForm.js"></script>
</head>
<body>
<form name="miForm" id="miForm" method="post" action="step2.asp">
    <div class="error" style="display:none;">
      <img src="images/warning.gif" alt="Warning!" width="24" height="24" style="float:left; margin: -5px 10px 0px 0px; " />
      <span></span>.<br clear="all"/>
    </div>
    <table>
        <tr><td><label>Unidades por paquete</label></td><td><input type="text" name="val_1" id="val_1" class="required" /></td></tr>
        <tr><td><label>Cantidad T</label></td><td><input type="text" name="val_2" id="val_2" class="required" math="#val_1,val3" /></td></tr>
        <tr><td><label>Paquetes</label></td><td><input type="text" name="val_3" id="val_3" value="5" disabled="disabled" /></td></tr>
        <tr><td><input type="submit" /></td></tr>
    </table>
</form>
</body>
</html> 
Código PHP:
"PAGINA validate_miForm.js"
// JavaScript Document
$(document).ready(function(){
    
jQuery.validator.addMethod("password", function( valueelement ) {
        var 
result this.optional(element) || value.length >= && /d/.test(value) && /[a-z]/i.test(value);
        if (!
result) {
            
element.value "";
            var 
validator this;
            
setTimeout(function() {
                
validator.blockFocusCleanup true;
                
element.focus();
                
validator.blockFocusCleanup false;
            }, 
1);
        }
        return 
result;
    }, 
"Your password must be at least 6 characters long and contain at least one number and one character.");

    
// a custom method making the default value for companyurl ("http://") invalid, without displaying the "invalid url" message
    
jQuery.validator.addMethod("defaultInvalid", function(valueelement) {
        return 
value != element.defaultValue;
    }, 
"");

    
jQuery.validator.addMethod("billingRequired", function(valueelement) {
        if ($(
"#bill_to_co").is(":checked"))
            return $(
element).parents(".subTable").length;
        return !
this.optional(element);
    }, 
"");
    
    
jQuery.validator.addMethod("math", function(value,param1,param2) {
        
alert(value);

                
//asi funciona, pero solo me trae el parametro1, el parametro2 me dice "undefined"
        
alert(jQuery(param1).val());
        
alert(jQuery(param2).val());
                
                
//Lo he intentado así y tampoco
                //jQuery.validator.addMethod("math", function(value,params) {    
                //alert(jQuery(params[0]).val());
        //alert(jQuery(params[1]).val());
        
        //return this.optional(element) || value == params[0] + params[1];
    
}, jQuery.validator.format("Please enter the correct value for {0} + {1}"));


    
//jQuery.validator.messages.required = "";
    
$("#miForm").validate({
        
invalidHandler: function(evalidator) {
            var 
errors validator.numberOfInvalids();
            if (
errors) {
                var 
message errors == 1
                    
'You missed 1 field. It has been highlighted below'
                    
'You missed ' errors ' fields.  They have been highlighted below';
                $(
"div.error span").html(message);
                $(
"div.error").show();
            } else {
                $(
"div.error").hide();
            }
        },
        
onkeyupfalse,
        
submitHandler: function() {
            $(
"div.error").hide();
            
alert("SUBMIT!!!");
        },
        
messages: {
            
password2: {
                
required" ",
                
equalTo"Please enter the same password as above"
            
},
            
email: {
                
required" ",
                
email"Please enter a valid email address, example: [email protected]",
                
remotejQuery.validator.format("{0} is already taken, please enter a different address.")
            }
        },
        
debug:true
    
});
}); 
Gracias de antemano.
__________________
"La adulación es una moneda que empobrece al que la recibe"

Etiquetas: Ninguno
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 12:42.