Monday, May 13, 2024
 Popular · Latest · Hot · Upcoming
2
rated 0 times [  5] [ 3]  / answers: 1 / hits: 43046  / 11 Years ago, fri, may 24, 2013, 12:00:00

I have simple question but I can't fined good solution on the web.



I have this HTML code:



 <form name=Register action=Register.aspx method=post runat=server style=margin-top: 15px; onsubmit=return validateProfile(this); >


And this JavaScript code



function validateProfile(F) {
var G = F.name;
}


I want somehow to get the form name, but this code just does not working.



wish for help, thanks!


More From » javascript

 Answers
12

There you go


function validateProfile(F) {
alert(F.name);
return false;
}

F is already the form, no need to use .Form .


Since a form is an element, you can access its name using .name.


This is defined in the DOM specification here :



name of type DOMString


Names the form.



Demo


Notice how my JSFiddle contains window.validateProfile = validateProfile because I run it after the DOM is ready, if your function is not directly in a script block, chances are you need to do this too.


[#78046] Thursday, May 23, 2013, 11 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
jenamackennac

Total Points: 304
Total Questions: 110
Total Answers: 107

Location: Ecuador
Member since Thu, Jun 4, 2020
4 Years ago
;