473,473 Members | 2,131 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

How do i get the form handle

Hi,

Let's say we have the following html code (a body with some forms):

<html>
<head>
</head>

<body>
<form name="form1" action="#">
<input type="image"
onmouseover="print_form_name()"
alt="Send"
value="1"
name="Send"
src="submit.gif"/>
</form>

<form name="form2" action="#">
<input type="image"
onmouseover="print_form_name()"
alt="Send"
value="2"
name="Send"
src="submit.gif"/>
</form>
</body>
</html>

I'm interested in the code of print_form_name() function. How can i
make it return the form handle, or run an alert with the form name, or
show me a list of controls of the current form (this is what i want).
Thanks in advance.

Regards,
Marius.

Apr 5 '07 #1
5 3814
On Apr 5, 1:13 pm, "mare...@gmail.com" <mare...@gmail.comwrote:
Hi,

Let's say we have the following html code (a body with some forms):

<html>
<head>
</head>

<body>
<form name="form1" action="#">
<input type="image"
onmouseover="print_form_name()"
alt="Send"
value="1"
name="Send"
src="submit.gif"/>
</form>

<form name="form2" action="#">
<input type="image"
onmouseover="print_form_name()"
alt="Send"
value="2"
name="Send"
src="submit.gif"/>
</form>
</body>
</html>

I'm interested in the code of print_form_name() function. How can i
make it return the form handle, or run an alert with the form name, or
show me a list of controls of the current form (this is what i want).
Thanks in advance.

Regards,
Marius.
well, here's a kind of fragile way to do it:

alert(this.parentNode.name);

in other words, your HTML would look like <input ...
onmouseover="alert(this.parentNode.name);" ... />

that should work, assuming that the <inputelement is the direct
child of the <formelement (like what you have now). if you were to,
say, put a table inside the <form>, and put the <inputinside the
table, it wouldnt work anymore because the code "this.parentNode"
would be getting the wrong element (probably a <tdor something like
that).

you could also try this:

alert(this.form.name);

it looks like that will work in firefox, but i'm not sure about other
browsers. i dont think that way is "proper" DOM, but it would
certainly be easier.

Apr 5 '07 #2
br*******@gmail.com said the following on 4/5/2007 2:26 PM:
On Apr 5, 1:13 pm, "mare...@gmail.com" <mare...@gmail.comwrote:
>Hi,

Let's say we have the following html code (a body with some forms):

<html>
<head>
</head>

<body>
<form name="form1" action="#">
<input type="image"
onmouseover="print_form_name()"
alt="Send"
value="1"
name="Send"
src="submit.gif"/>
</form>

<form name="form2" action="#">
<input type="image"
onmouseover="print_form_name()"
alt="Send"
value="2"
name="Send"
src="submit.gif"/>
</form>
</body>
</html>

I'm interested in the code of print_form_name() function. How can i
make it return the form handle, or run an alert with the form name, or
show me a list of controls of the current form (this is what i want).
Thanks in advance.

Regards,
Marius.

well, here's a kind of fragile way to do it:

alert(this.parentNode.name);
Very very fragile.
in other words, your HTML would look like <input ...
onmouseover="alert(this.parentNode.name);" ... />

that should work, assuming that the <inputelement is the direct
child of the <formelement (like what you have now). if you were to,
say, put a table inside the <form>, and put the <inputinside the
table, it wouldnt work anymore because the code "this.parentNode"
would be getting the wrong element (probably a <tdor something like
that).

you could also try this:

alert(this.form.name);
And it will always work if the form has a name and if the input element
is a child of a form.
it looks like that will work in firefox, but i'm not sure about other
browsers.
It does.
i dont think that way is "proper" DOM, but it would certainly be easier.
Why wouldn't it be? Form control was around long before the concept of a
"proper DOM".

--
Randy
Chance Favors The Prepared Mind
comp.lang.javascript FAQ - http://jibbering.com/faq/index.html
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
Apr 5 '07 #3
ma*****@gmail.com wrote:
Hi,

Let's say we have the following html code (a body with some forms):

<html>
<head>
</head>

<body>
<form name="form1" action="#">
<input type="image"
onmouseover="print_form_name()"
alt="Send"
value="1"
name="Send"
src="submit.gif"/>
</form>

<form name="form2" action="#">
<input type="image"
onmouseover="print_form_name()"
alt="Send"
value="2"
name="Send"
src="submit.gif"/>
</form>
</body>
</html>

I'm interested in the code of print_form_name() function. How can i
make it return the form handle, or run an alert with the form name, or
show me a list of controls of the current form (this is what i want).
Instead of
onmouseover="print_form_name()"
use onmouseover="print_form_name(this)"

Then your JS for

print_form_name()

becomes

function print_form_name(x) { // x is the passed parameter
theFormName = x.form.name; //string
alert(theFormName);
theForm = document.forms[theFormName]; //the form object
theElem = theForm.elements; //collection of the form's elements
}
Apr 5 '07 #4
Lee
no said:
>
ma*****@gmail.com wrote:
>Hi,

Let's say we have the following html code (a body with some forms):

<html>
<head>
</head>

<body>
<form name="form1" action="#">
<input type="image"
onmouseover="print_form_name()"
alt="Send"
value="1"
name="Send"
src="submit.gif"/>
</form>

<form name="form2" action="#">
<input type="image"
onmouseover="print_form_name()"
alt="Send"
value="2"
name="Send"
src="submit.gif"/>
</form>
</body>
</html>

I'm interested in the code of print_form_name() function. How can i
make it return the form handle, or run an alert with the form name, or
show me a list of controls of the current form (this is what i want).

Instead of
onmouseover="print_form_name()"

use onmouseover="print_form_name(this)"

Then your JS for

print_form_name()

becomes

function print_form_name(x) { // x is the passed parameter
theFormName = x.form.name; //string
alert(theFormName);
theForm = document.forms[theFormName]; //the form object
x.form already IS the form object.
In fact, if they set onmouseover="print_form_name(this.form)",
then x will be the form object.
--

Apr 5 '07 #5
Thanks a lot. Very useful tips from all of you

Apr 15 '07 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Job Lot | last post by:
I have requirement where client has to call us to get a key to access a particular form. Secondly, I want the code to be valid for a day. Can some guide me in right direction to implement this...
14
by: Abhi | last post by:
FYI: This message is for the benefit of MS Access Community. I found that this prblem has been encounterd by many but there is hardly any place where a complete solution is posted. So I thought...
5
by: Ignacio X. Domínguez | last post by:
Hi. I have created a component (System.ComponentModel.Component) that I place on a form. Is there a way of obtaining the Form.Handle of the form where I have placed my component? Thank you
2
by: Sgt. Sausage | last post by:
Problem. Work-around. No issues, just looking to see if I'm the only one that's seen this. I just lost 3 hours (shoulda found it sooner) to the InvokeRequired on a form being somewhat...
19
by: Oliver Neumann | last post by:
Hello, im new to c# and i got an app with a notifyicon. Now i want to start the app only with the notifyIcon, so that the Main-Form doesnt show up. The form itself is used at the entrance...
3
by: Richard L Rosenheim | last post by:
I have the application's form (MainForm) along with a 2nd form (Form2). If the user minimizes MainForm, I also minimize Form2. And when the user restores the application, I also restore Form2. ...
4
by: Arsalan | last post by:
In MDI interface, suppose i have a form named "FORM" , how do i check if its already loaded or not ??
2
by: Melisa | last post by:
Hi, How can i create bitmap of a window form with all its child controls without showing this form? 1. I am trying to create bitmap image of a window form. 2. I am creating a new instance of...
5
by: RichG | last post by:
I'm looking for a way to bring an open form to the top. I know that is I open a form directly with form1.show() and then later, while the form is open I do another form1.show(), that I will get...
4
by: =?GB2312?B?0rvK18qr?= | last post by:
Hi all, Today I was writing a simple test app for a video decoder library. I use python to parse video files and input data to the library. I got a problem here, I need a windows form, and...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.