Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Getting the form name

Status
Not open for further replies.

newbiepg

Programmer
Nov 6, 2002
181
IN
I have documents that have 2 or more forms in them.The number of forms varies.
I am trying to create a common validation function for some of them.
My question is , how can I get the form name from within the form.
I need to pass the form name as a parameter
e.g.

<form name=&quot;one&quot; action=&quot;someplace&quot; method=&quot;post&quot;>
some code
</form>

</form name=&quot;two&quot; action=&quot;someplace2&quot;>
<input type=&quot;button&quot; onClick=&quot;javascript:myfunction('need the formname here')&quot;>
</form>
 
<input type=&quot;button&quot; onClick=&quot;javascript:myfunction(this.form.name)&quot;>



Greetings, Harm Meijer
 
Harm Meijer

This code works well when I am using a js function within the head tags

But when I use an external js file, that just returns an error

'this.null.form is null or not an object'

I am using internet explorer 5.5

any ideas?

Thanks
 
Hello,

Plse tell me why u use 2 forms in a single page?

And what's the need of JS file?

Regards,
Prkash.A
 
What I like to know how you get the following line:
<input type=&quot;button&quot; onClick=&quot;javascript:myfunction(this.form.name)&quot;>
in a js file, it is html not script.



Greetings, Harm Meijer
 
The line
<input name=&quot;what is my name&quot; type=&quot;button&quot; onClick=&quot;javascript:myfunction(this)&quot;>

Passes itselve as the first (and only parameter) to the myfunction function.
if your myfunction looks like this:
function myfunction(HTMLobject){
alert(HTMLobject.type);
alert(HTMLobject.name);
}
It would alert &quot;button&quot; and then &quot;what is my name&quot;, this is a keyword in javascript meaning &quot;the thing that raises the onclick will pass itselve&quot;. In vb this is known as Me.

Plese check that the keyword is not enclosed in quotes.




Greetings, Harm Meijer
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top