473,573 Members | 2,810 Online
Bytes | Software Development & Data Engineering Community
+ 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="pr int_form_name() "
alt="Send"
value="1"
name="Send"
src="submit.gif "/>
</form>

<form name="form2" action="#">
<input type="image"
onmouseover="pr int_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 3828
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="pr int_form_name() "
alt="Send"
value="1"
name="Send"
src="submit.gif "/>
</form>

<form name="form2" action="#">
<input type="image"
onmouseover="pr int_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.pare ntNode.name);

in other words, your HTML would look like <input ...
onmouseover="al ert(this.parent Node.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.parentNod e"
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="pr int_form_name() "
alt="Send"
value="1"
name="Send"
src="submit.gif "/>
</form>

<form name="form2" action="#">
<input type="image"
onmouseover="pr int_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.pare ntNode.name);
Very very fragile.
in other words, your HTML would look like <input ...
onmouseover="al ert(this.parent Node.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.parentNod e"
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.javas cript FAQ - http://jibbering.com/faq/index.html
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
Apr 5 '07 #3
ma*****@gmail.c om 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="pr int_form_name() "
alt="Send"
value="1"
name="Send"
src="submit.gif "/>
</form>

<form name="form2" action="#">
<input type="image"
onmouseover="pr int_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="pr int_form_name() "
use onmouseover="pr int_form_name(t his)"

Then your JS for

print_form_name ()

becomes

function print_form_name (x) { // x is the passed parameter
theFormName = x.form.name; //string
alert(theFormNa me);
theForm = document.forms[theFormName]; //the form object
theElem = theForm.element s; //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="pr int_form_name() "
alt="Send"
value="1"
name="Send"
src="submit.gif "/>
</form>

<form name="form2" action="#">
<input type="image"
onmouseover="pr int_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="pr int_form_name() "

use onmouseover="pr int_form_name(t his)"

Then your JS for

print_form_name ()

becomes

function print_form_name (x) { // x is the passed parameter
theFormName = x.form.name; //string
alert(theFormNa me);
theForm = document.forms[theFormName]; //the form object
x.form already IS the form object.
In fact, if they set onmouseover="pr int_form_name(t his.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
1606
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 requirement? How should I generate this code, validate it and let the code be active for a day? Thanks
14
10117
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 I should give back to the community by posting our findings. Thanks you all for all your help till now by posting problems and their solutions. ...
5
2487
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
4841
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 unreliable. It will sometimes return incorrect results. I've got it isolated to the Form's Handle property. If nothing touches my form's Handle before the...
19
24720
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 point of the app: Application.Run(new MainFrame()); Now i tried to use this to hide the Form and show up the trayBarIcon with this in the constructor...
3
3215
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. But, Form2 is ending up behind MainForm. Anyone have an idea of how can I set/keep Form2 to be in front of the MainForm? And before someone...
4
1483
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
8364
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 Form at runtime. 3. Then adding several controls like Button, RadioButton,CheckBox etc to it. 4. Now i want to create bitmap with all controls...
5
3067
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 original form to pop to the top. But because I want to have multiple instances of form1 open, I open it with dim frm as new form1 frm.show() ...
4
3577
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 send the form handle to the library as a parameter, then it can output video on the form. Here is my problem:
0
7707
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
8037
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8213
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
0
8080
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6430
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5604
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5296
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3737
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3742
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

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.