javascript - How to get content length of invalid input? -
javascript - How to get content length of invalid input? -
i have element:
<input type="number"> when type in $500, fails validation,
console.log("el.value"); //returns "" this expected.
here's question: how can check there content?
i'm trying show/hide placeholder text (no, can't utilize native stuff). needs type="number" because need forcefulness mobile number keyboard.
any thoughts?
update: responses below can see wasn't clear plenty in question.
1) need utilize javascript tell me whether there content in input. (i don't need extract it, need see whether there content).
this tricky, because invalid content (like putting words in number input field) means value="" if there content typed in.
this exact problem need solve.
inputel.validity.valid might work can't find docs on how supported across browsers.
check if can :
html
<input id="my-input" type="number"> js
$(document).ready(function(){ $('#my-input').on('input', function(){ console.log($(this).val()); }); }); javascript jquery html
Comments
Post a Comment