Hi,
I do not understand some code which I have used. I can see what it is doing and have implemented it successfully but cannot seem to validate it.
I have a form where by a course can be added. On this form I have a button which will allow the user to add levels dynamically as many as 10. This is to save time so that they dont have to input the same data over and over again for the various levels. This works fine and I am successfully writing to the database. The problem is that I want to check all of the level fields that have been added to make sure that they are not left blank.
The code is as follows:
Any advice would be much appreciated so that I can validate all of the fields making sure they are not NULL.Code:// This function will dynamically add level fields to the form. var counter = 1; var limit = 10; function addInput(divName) { if (counter == limit) { alert("You have reached the limit of adding " + counter + " inputs"); } else { var newdiv = document.createElement('div'); newdiv.innerHTML = "<label>Level"+ (counter)+ ": *</label><input type='text' name='levels[]'>"; document.getElementById(divName).appendChild(newdiv); counter++; } } // The form button to add a new level calling above function <div id="dynamicInput"> <input type="button" value="Add level" onClick="addInput('dynamicInput');"> </div>
Thanks in advance


Reply With Quote
Bookmarks