I am unable to get length of textbox
$('input[id$=textinput1]').val().length
returns nothing
I cannot use $('#textinput1').val().length - although this works
Update: My Element looks like this
<input id="textinput1" type="text" />
I am unable to get length of textbox
$('input[id$=textinput1]').val().length
returns nothing
I cannot use $('#textinput1').val().length - although this works
Update: My Element looks like this
<input id="textinput1" type="text" />
Give it a name then (it should have one anyway), e.g. name="textinput1", and then use
$("input[name='textinput1']").val().length
This is probably because the query returns more than one element. If that is the case, then go through each one and get the length of the text in each textbox, or get the textbox you want and get the length of the text in it.
var el = $('input[id$=mode]');
if ( el.length ) {
alert( $(el).val().length )
}
Remember $= denotes it ends with 'mode'
Why are you using 'id$=textinput1', rather than 'id=textinput1'? The first expression checks for an id that ends in 'textinput1', whereas you need to check for an exact value, as far as I can see, so you should be using the second expression.
If you have another element whose id ends with 'textinput1', then this will explain why the query is returning more than one element.
I also echo @piquadrat's question - why can you use "$('#textinput1').val().length"?