473,394 Members | 1,865 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

form property and object

Hello,

I'm new to this newsgroup and I have small question.

With something like this : <form name="a"><input name="name"></form>
Is it possible to get the name of the form (a) and access the input object
(name) too ?

Thanks,
/mathieu

Jul 20 '05 #1
3 6684
In article <gI*********************@nnrp1.uunet.ca>, "mathieu gagnon"
<ma**@netc.net> writes:
I'm new to this newsgroup and I have small question.

With something like this : <form name="a"><input name="name"></form>
Is it possible to get the name of the form (a) and access the input object
(name) too ?

Thanks,
/mathieu

<form name="myForm">
<input type="button" onclick="alert(this.form.name)"
value="Click Me to see the Forms Name">
<input type="button" onclick="alert(this.name)"
value="Click Me to see My Name" name="myInput">
<input type="button"
onclick="alert('This input is in the ' + this.form.name + ' form. And my
input name is ' + this.name)"
value="Click Me to see the Forms Name and My Name" name="myInput2">
</form>

alert(document.forms[0].elements[1].name)
alert(document.forms[0].name)

In short, you access the form elements name property, or the elements name
property.

HTH
--
Randy
All code posted is dependent upon the viewing browser
supporting the methods called, and Javascript being enabled.
Jul 20 '05 #2
If I try...

<form name="a"><input name="name"></form>
alert(document.forms[0].elements[1].name)
alert(document.forms[0].name)

The first alert gives "name", the second : "[object]".
What I need is "a" alerted without changing the name of the input.

Thanks,
/mathieu

"HikksNotAtHome" <hi************@aol.com> a écrit dans le message de
news:20***************************@mb-m14.aol.com...
In article <gI*********************@nnrp1.uunet.ca>, "mathieu gagnon"
<ma**@netc.net> writes:
I'm new to this newsgroup and I have small question.

With something like this : <form name="a"><input name="name"></form>
Is it possible to get the name of the form (a) and access the input object(name) too ?

Thanks,
/mathieu

<form name="myForm">
<input type="button" onclick="alert(this.form.name)"
value="Click Me to see the Forms Name">
<input type="button" onclick="alert(this.name)"
value="Click Me to see My Name" name="myInput">
<input type="button"
onclick="alert('This input is in the ' + this.form.name + ' form. And my
input name is ' + this.name)"
value="Click Me to see the Forms Name and My Name" name="myInput2">
</form>

alert(document.forms[0].elements[1].name)
alert(document.forms[0].name)

In short, you access the form elements name property, or the elements name
property.

HTH
--
Randy
All code posted is dependent upon the viewing browser
supporting the methods called, and Javascript being enabled.

Jul 20 '05 #3
In article <yS*********************@nnrp1.uunet.ca>, "Mathieu Gagnon"
<ma**@netc.net> writes:
If I try...

<form name="a"><input name="name"></form>
alert(document.forms[0].elements[1].name)
alert(document.forms[0].name)

The first alert gives "name", the second : "[object]".
What I need is "a" alerted without changing the name of the input.


The reason you are getting object is because you have a form input named "name"
and as such, instead of trying to access the form's name property, it is
accessing the field element named name, which is an object. Thats part of why
you should never name form inputs (or ids, or classes), the same as an HTML
attribute.

If you are going to try to access the name of a form that has an input named
name,
you may want to try renaming the input, programattically, and then renaming it
after getting the form name:

document.forms[0].elements["name"].name = "someThingElse";
alert(document.forms[0].name);
document.forms[0].elements["someThingElse"].name = "name"

Another alternative, if you are just dead set on having it named "name", is to
capitalize it "Name" and then it won't interfere.

HTH

--
Randy
All code posted is dependent upon the viewing browser
supporting the methods called, and Javascript being enabled.
Jul 20 '05 #4

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

Similar topics

2
by: Sam Goffin | last post by:
Hi how can I resize my form borders in .NET (either VB or C#)? In one of my programs I want to extend the usual form size at one end (when the user clicks the "Details..." button), so I need...
10
by: Gregory A Greenman | last post by:
I'm trying to write a program in vb.net to automate filling out a series of forms on a website. There are three forms I need to fill out in sequence. The first one is urlencoded. My program is...
4
by: Stuart Perryman | last post by:
Hi, I have the following code which works just fine in IE6 but not in Firefox. It is an extract of several table rows each with an individual form. It is generated by php. <form...
1
by: kyma via .NET 247 | last post by:
Hi, I haveto use VB to create a form that reads an exisiting XML fileand then allows updates via the VB form. My problem is that I was able to get VB to read a simple XML file(people.XML), but...
21
by: Simon Verona | last post by:
Hope somebody can help! I want to automatically be able to add code to the initialize routine on a Windows form when I add a custom control that I've written to a form. Specifically, I'm trying...
3
by: BakelNB | last post by:
I am new to the .Net environment, so please bear with me. I am passing a form object (e.g. formA) to an existing form (e.g. formB) by setting a property value defined in formB to hold the formA...
11
by: Rik | last post by:
Hello guys, now that I'm that I'm working on my first major 'open' forms (with uncontrolled users I mean, not a secure backend-interface), I'd like to add a lot of possibilities to check wether...
2
by: Ralph | last post by:
Hi I don't understand why it's not working: function schedule(imTop){ this.tdImagesTop = imTop; } schedule.prototype.selectEl = function() { alert(this.tdImagesTop);
12
by: Rob | last post by:
Let's say you open Form1 that contains TabControl1 There are several tabs on TabControl1 Now you open a new Form2 that contains a User Control How can you determine the Selected tab in Form1...
9
by: dhtml | last post by:
I have written an article "Unsafe Names for HTML Form Controls". <URL: http://jibbering.com/faq/names/ > I would appreciate any reviews, technical or otherwise. Garrett --...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
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...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

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.