forms - jQuery: textfield name selector -


i have form:

<form id="userform" action="xpto">      <input type="text" name="form[data_nascimento_beneficiario_1]" value />      <input type="submit" value="continuar" /> </form> 

now on script file try lenght of field validation:

$("#userform").submit(function (e) {      alert($("input[name="form[data_nascimento_beneficiario_1]"]).length()); }); 

but "typeerror: cannot call method 'length' of null",

i guess problem on name have "form[]", nothing can change :(

can me please?

regards all.

a few issues there:

  1. your code quoted has syntax error , wouldn't give error you've said, you've ended javascript string after word name.

  2. when attribute value you're testing contains letters a-z, it's best put in quotes.

  3. length "th" @ end, not "ht"

  4. ...and in jquery it's property, not method, don't want () after it

  5. the name you're using in selector (data_nascimento_baneficiario_1) doesn't match name in form (data_nascimento_beneficiario_1), note "a" @ beginning of "baneficiario" in selector.

all together: live example | source

alert($('input[name="form[data_nascimento_beneficiario_1]"]').length); 

(there, i've used ' put quotes around selector string , " put quotes around attribute value. other way around works.)


Comments

Popular posts from this blog

c++ - CryptStringToBinary API behavior -

c++ - Correct method for redrawing a layered window -

java.util.scanner - How to read and add only numbers to array from a text file -