Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get name of form element

Tags:

javascript

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;     } } 
like image 494
SomeoneS Avatar asked Jun 13 '12 17:06

SomeoneS


People also ask

How do I get the name of an element in HTML?

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.

What are the form elements?

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.

How do I get a tag name?

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.


1 Answers

var name = element.getAttribute("name"); 
like image 135
Dave Rager Avatar answered Sep 22 '22 03:09

Dave Rager