Answer the question
In order to leave comments, you need to log in
How to include your javascript in react?
Inside react
<input id="txtF" type="number" onKeyPress="return check(event,value)" onInput="checkLength(3,this)" />
<input type="number" onKeyPress="return check(event,value)" onInput="checkLength(4,this)" />
<input type="number" onKeyPress="return check(event,value)" onInput="checkLength(5,this)" />
function checkLength(len,ele){
var fieldLength = ele.value.length;
if(fieldLength <= len){
return true;
}
else
{
var str = ele.value;
str = str.substring(0, str.length - 1);
ele.value = str;
}
}
export default checkLength;
Answer the question
In order to leave comments, you need to log in
onInput="checkLength(3,this)"
jsx is not html. Event Handling in JSX . And in general, you need to read more about JSX.
Strange use of this, it will not point where it is needed, if the DOM element is so needed, then you need to pull it out of the event:
<input id="txtF" type="number" onInput={e => checkLength(3, e.target)} />
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question