I setup a script and is working fine, however I want to use some pieces of that code, since I did not want to create repetitive lines of code I wanted to put them inside functions and then call those functions within a function, but for some reason is not working, so I decided to do a test applying that concept and here is what I did:
Supposedly that previous code should highlight the field in red and give a warning when someone enters numbers and give a “correct!” word and highlight in yellow when only letters are entered, and if updated the check should be done again right?
<input type="text" id="myid" size="15">
var NOnumbershere=new RegExp(/\d/);
if (NOnumbershere.test(thevalue) == true)
document.getElementById("errors_console_1").innerHTML = ("No numbers allowed");
thefield.style.background = "#FF0000";
document.getElementById("errors_console_1").innerHTML = ("Correct!");
thefield.style.background = "#FFFF00";
thefield.addEventListener("change", validate_text, false);
But since it is not working I suppose I am doing something wrong, because it does something random every time, sometimes I enter numbers and gives me the word correct and highlights in yellow, sometimes I enter only letters and it gives me an error and highlights in red and sometimes it works fine the first check but not the second or third etc.
Can someone help me on this?