Passing String Variable as Parameter in JavaScript/jQuery -
i have ajax request returns following text , assigns javascript variable called authcodes
. text ajax request: value === '1' || value === '2' || value === '3'
.
the following code works text manually inserted.
$.validator.addmethod("authcode", function(value, element, param) { return this.optional(element) || (value === '1' || value === '2' || value === '3'); }, "please enter valid access code.");
however, when try put variable authcodes
in, function not work. here variable inserted instead of manually.
$.validator.addmethod("authcode", function(value, element, param) { return this.optional(element) || (authcodes); }, "please enter valid access code.");
this code related form validation , seems second method, contents of text input ignored , lets value through. whereas first method, values of 1, 2, , 3 let through.
any appreciated , thank time in advance.
you comparing string here. if want execute code ajax reply use javascripts's eval
. beware can dangerous though because code executed. changing work:
$.validator.addmethod("authcode", function(value, element, param) { return this.optional(element) || eval(authcodes); }, "please enter valid access code.");
it better list of acceptable values , check if value have in list.
Comments
Post a Comment