i have this simple JS for validating form, can someone tell me how to get name of field (you know, name=""), it should be where NameOfSomefield is now :S I tried with someField.tagName
but no luck...
function validateForm(){ var someField = document.forms["nameofofrm"]["someField"].value; if (someField==null || someField=="") { alert("You cannot leave blank this field: ".NameOfSomefield); return false; } }
JavaScript – Tag Name of an HTML Element To get the tag name of a specific HTML Element as a string, using JavaScript, get reference to this HTML element, and read the tagName property of this HTML Element. tagName is a read only property that returns the tag name of this HTML Element as a string.
form elements. . </form> The <form> element is a container for different types of input elements, such as: text fields, checkboxes, radio buttons, submit buttons, etc. All the different form elements are covered in this chapter: HTML Form Elements.
Introduction to JavaScript getElementsByTagName() method The getElementsByTagName() is a method of the document object or a specific DOM element. The getElementsByTagName() method accepts a tag name and returns a live HTMLCollection of elements with the matching tag name in the order which they appear in the document.
var name = element.getAttribute("name");
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With