JavaScript - Help To Wannabe Js Programmer... Please
Hey,
I am self-learning Javascript. I am going through an online course right now and I am roadblocked. I wish I had a teacher by my side at times. Despite viewing and reviewing the material, I just cannot get a good enough grasp to keep going with the course. The code below is aimed at forcing the user to enter valid valid information in input fields. Here are my questions in orange: Code: window.onload = initForms; function initForms() { for (var i=0; i< document.forms.length; i++) { document.forms[i].onsubmit = function() {return validForm();} // I don't understant the syntax on the right side the the '='... Why do we need 'function ()'... why not '= validForm() instead? } } function validForm() { var allGood = true; var allTags = document.getElementsByTagName("*"); for (var i=0; i<allTags.length; i++) { if (!validTag(allTags[i])) { allGood = false; } } return allGood; // from that point on, I am having a difficult time understanding the relations between the 2 functions function validTag(thisTag) { var outClass = ""; var allClasses = thisTag.className.split(" "); for (var j=0; j<allClasses.length; j++) { outClass += validBasedOnClass(allClasses[j]) + " "; } thisTag.className = outClass; if (outClass.indexOf("invalid") > -1) { thisTag.focus(); if (thisTag.nodeName == "INPUT") { thisTag.select(); } return false; } return true; function validBasedOnClass(thisClass) { var classBack = ""; switch(thisClass) { case "": case "invalid": break; case "reqd": if (allGood && thisTag.value == "") { classBack = "invalid "; } classBack += thisClass; break; case "radio": case "email": classBack += thisClass; break; default: if (allGood && !crossCheck(thisTag,thisClass)) { classBack = "invalid "; } classBack += thisClass; } return classBack; } function crossCheck(inTag,otherFieldID) { if (!document.getElementById(otherFieldID)) { return false; } return (inTag.value == document.getElementById(otherFieldID).value); } } } Can someone out there put a smile on my face? Similar TutorialsHey I'm new to programming (actually news not even the word for it) and I need some help. I plan on going to college to study game development and programming but I have no idea how to program. If you could post some links to beginner tutorials or even type one up for me, it would be greatly appreciated. Oh, and I'm planning on trying Java first, but if you have another suggestion, it would help. Also, I have blender and have made simple games on it, but I don't really like the 3D modelling concept. I wanted to try coding now so, thanks in advance! P.S. I don't even know how to oped up Java... I downloaded Java SE DK 6u15 (I do know what it stands for though!) but I'm not sure if I did it right or not. So basically a 100% complete tutorial from downloading to... whatever the last step is. Thanks! Hi Guys & Girls, I am looking for help with a technical issue, which my programmer can't find the answer to. My website has a demonstration facility which allows a client to enter their website which then in turn creates a video transparency overlaying their own website. The problem is some sites with Flash, overlay my transparency video so that you cant see my demo video. Any ideas please. Thanks Maximillion |