So for a school project we had to make a page which had a form, a bunch of fields and a submit in html. The formatting was done in an external CSS file. Finally, we had to code some validation for the form in an external javascript file. So in the end, the page 'consisted of' 3 files.
One of the demands of validation was that a textfield that didn't meet the requirements would get a red border. I achieved this at first, when I was still working with all the javascript between script-tags in the original html file, by adding a class to my CSS file:
.error {
border:2px solid red;
}
And adding it to the element concerned with javascript:
document.getElementById("naam").className = document.getElementById("naam").className + " error";
I used the following code to revert the changes once the field met the requirements (e.g. outside any if-tags)
document.getElementById("naam").className = document.getElementById("naam").className.replace(" error", "");
Now, however, in order to meet the last requirement I moved all my javascript to a separate file, java.js, and linked to it in the html.
<script src="java.js"></script>
Everything works, except for the css alteration, and I can't really figure out how or why.
Whoop it IS working; I just didnt see it because it doesn't fit the page quite right (the elements that will recieve a red border are all at the top of the page, whereas the button is all the way at the bottom). Before though, the red border would stay untill the textfield met requirements. Now, it resets the page after all the alerts I set, before I get a chance to see they're red. So, I guess the real problem is that the page resets, it empties all textfields, en resets the css.