But it was implemented check processing in the input item after a specified time and when the focus is out, and exit to the JavaScript function, view and has an error message twice display in the alert will be called both for processing there is no Will be done.
I want to issue an alert only once. I want to check every time I get out of focus. I want to check even after the specified time has passed.
main.js
function isTimecheck() {
setTimeout("onAutoSave()",Specified time);
}
function onAutoSave() {
var result = true;
var a =Input items.value; //Get the input value of the input item.
var maxLen = 20; //Maximum number of characters: 20 in the example.
if (a != '') {
result = WordCountCheck(a, maxlen);
if (result == false) {
alert(Error message);
Input items.focus(); //Return the focus to the input item.
return false;
}
}
}
window.onload = function(){
isTimeCheck();
}
check.js
function WordCountCheck(str, maxLength) {
var i = 0;
var len = 0; //Store the number of bytes.
str.value = rightTrim(str.value);//Delete unnecessary right space.
var val = str.value;
if(val !=""){
for(; i<val.length; i++) {
If it is half-width, it is 1 byte, so add 1 to len.
If it is full-width, it is 2 bytes, so add 2 to len.
}
if(maxLength < len){
alert(Error message);
str.focus(); //Return the focus to the input item.
return false;
}
}
}
Test.html
<TD>
<textarea cols="" rows="" name="" style="" onBlur="WordCountCheck(this, 20);">Input items</textarea>
</TD>
This HTML part
<TD>
<textarea cols="" rows="" name="" style="" onChange="WordCountCheck(this, 20);">Input items</textarea>
</TD>
In this case, when I tried with the same data as onBlur, the pop-up appeared only once, but if this is the case, the value changes and an error message appears and then the focus is out without changing. I'm dissatisfied because I can't check it.
Also, the check process is described in another js file.
As a response, I am now wondering if the following is feasible. (1) Check only onBlur, and if there is an error, exit the process at the beginning of onAutoSave. (2) Prevent the onBlur process from being called when the specified time has elapsed. ③ If a check error occurs in the one called first by onBlur or onAutoSave, the process is exited at that point (I think this is possible if the process of exit can be realized ...).
In the first place, in the case of this implementation, which of onBlur and onAutoSave will be executed first after the specified time has elapsed?
When I tried to make the onBlur part as follows (listed in JS for easy viewing), of course, it is not checked at the time of lost focus, and it is not checked even after the specified time has passed. It seems that onAutoSave was called earlier, so if a check error occurs there, I tried to set the global variable checkFlg to true so that onBlur processing is not performed. However, the alert appears twice.
onBlur="isLostFocusCheck(this);"
var checkFlg=false;
function isLostFocusCheck(str) {
if(checkFlg==false) { //If there is a check error in auto save, checkFlg is true and this if should be passed through.
WordCountCheck(str, 20);
}
}
Recommended Posts