473,786 Members | 2,771 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to read Form name?

Hello,

I have a javascript function that I want to read the name of the form
which is calling it.

Here is my HTML:

<HTML>
<HEAD>
<SCRIPT LANGUAGE="JavaS cript">
function formNameTest(oT his)
{
alert('Form name is "'+oThis.form.n ame+'"')
}
</SCRIPT>
</HEAD>
<BODY>
<FORM NAME="Test">
<INPUT TYPE="TEXT" NAME="TestText" onClick="formNa meTest(this)">
</FORM>
</BODY>
</HTML>

and what it ends up displaying in the alert window is "[object]" instead of
the form's name. I have also tried using 'oThis.form.nam e.value' which
gives "".
And finally, I tried passing 'this.form' to my fuction (and modified my
function) instead of 'this', with no luck.

So, how can this be done?

Thanks in advance,
Scott Navarre
Jul 20 '05 #1
3 1549
<html><body>

<script language="JavaS cript">
function formName(theFor mName){
alert(theFormNa me);
}
</script>
<form name="myForm">
<input type="text" name="theButton "
onClick="formNa me(this.form.na me);">
</form>

</body></html>

Brynn
www.coolpier.com

I participate in the group to help give examples of code.
I do not guarantee the effects of any code posted.
Test all code before use!

On Wed, 21 Jan 2004 01:39:32 -0700, "Scott Navarre" <sm*@asus.net >
wrote:
Hello,

I have a javascript function that I want to read the name of the form
which is calling it.

Here is my HTML:

<HTML>
<HEAD>
<SCRIPT LANGUAGE="JavaS cript">
function formNameTest(oT his)
{
alert('Form name is "'+oThis.form.n ame+'"')
}
</SCRIPT>
</HEAD>
<BODY>
<FORM NAME="Test">
<INPUT TYPE="TEXT" NAME="TestText" onClick="formNa meTest(this)">
</FORM>
</BODY>
</HTML>

and what it ends up displaying in the alert window is "[object]" instead of
the form's name. I have also tried using 'oThis.form.nam e.value' which
gives "".
And finally, I tried passing 'this.form' to my fuction (and modified my
function) instead of 'this', with no luck.

So, how can this be done?

Thanks in advance,
Scott Navarre


Brynn
www.coolpier.com

I participate in the group to help give examples of code.
I do not guarantee the effects of any code posted.
Test all code before use!
Jul 20 '05 #2
"Scott Navarre" <sm*@asus.net > wrote in message
news:bu******** *@enews4.newsgu y.com...
<snip>
function formNameTest(oT his)
{
alert('Form name is "'+oThis.form.n ame+'"')
}
</SCRIPT>
</HEAD>
<BODY>
<FORM NAME="Test">
<INPUT TYPE="TEXT" NAME="TestText" onClick="formNa meTest(this)">
</FORM>
</BODY>
</HTML>

and what it ends up displaying in the alert window is
"[object]" instead of the form's name. I have also tried
using 'oThis.form.nam e.value' which gives "".
And finally, I tried passing 'this.form' to my fuction
(and modified my function) instead of 'this', with no luck.


When you post code claming that it demonstrates a problem it is a good
idea to test it to ensure that id does exhibit the problem. The code you
posted will not exhibit the problem described because that is being
caused by one of the controls that you have placed within the real form
HTML having the name (or possibly ID) "name". When the reference to that
control is added to the form as a named property of the form, under its
name "name" it overwrites the form's original - name - property and
renders the name of the form inaccessible to scripts.

If you had tested the code you posted you would have noticed it working
and had reason to suspect that it was a difference between that code and
the original that explained the problem.

It is best to never give the controls within a form NAME (or ID)
attributes that correspond with existing properties of the form object.
And it is easy to avoid as JavaScript is case sensitive so only changing
to initial capitals in the control names would avoid the problem
entirely.

Richard.
Jul 20 '05 #3
Yes, you are right! I had a text input with NAME="name"!

I didn't know it would override the form's .name attribute. Thank you
very much for explaining this! And for knowing exactly what I did without
seeing my original code. You're good...

So then you would suggest to start all HTML form element names with
capital letters to never run into a problem like this again?
I guess I am just use to JavaScript's variable naming convention of always
using lowercase letters for the first letter of the variable.
I am not sure I would have realized the problem even if I knew my example
worked...
Jul 20 '05 #4

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

Similar topics

4
9441
by: Mikko | last post by:
Is it possible to read "label" from form-field? <label for="product1">bread</label> <input id="product1" name="product1" type="text" size="3"> number comes with $_GET; but how do I read the "bread"?
3
2707
by: Pavils Jurjans | last post by:
Hello, I have bumped upon this problem: I do some client-side form processing with JavaScript, and for this I loop over all the forms in the document. In order to identify them, I read their "name" property (which sources from "name" HTML attribue). The problem is, that if the form contains form control named "name", it overwrites the form name property. In fact, I'm quite surprised that it's so easy to spoil any of the form object...
2
9209
by: /.. | last post by:
Hi all, I'm working on a report display page that currently uses 5 checkboxlists with a total of 86 items to display values from 5 different tables in an Access database. The page works fine now. On presenting it to the users they pointed out that their users could change the values in the checkboxes and then print them out, ultimately documenting false information.
12
2880
by: James Norton-Jones | last post by:
Hi, Am I trying to hold the data of a DataGrid in a label so that when the form is reposted the DataGrid can be repopulated. The problem I am having is that I don't understand how to get the text into a stream in order to be able to use DataSetOutcomes1.ReadXML(MyStream). Thanks in advance, James
17
15550
by: ronaldlee | last post by:
I have this error in Line 89. Collection is read-only. Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. Exception Details: System.NotSupportedException: Collection is read-only.
2
1825
by: Vish | last post by:
Hi, I amplanning on having a rea-only and edit states for my form. But it do not want my form and its controls to look different or disabled. I am planning on having a edit button that brings the form from read-only to a edit state. Is there any easy or built-in way of doing this in .NET? My preimary purpose for doing it because the combobox controls on my form take a while to load all their data from the database. Since the user uses...
0
2889
by: vishnu | last post by:
Hi, Am trying to post the data over https and am getting error in httpwebresponse.getResponseStream.Please help me to get rid of this issue. Here is the message from immediate window ?myResp.GetResponseStream() {System.Net.ConnectStream}
4
4891
by: Michael Munch | last post by:
Hi I want to read the value of af text-field, create dynamic, in a form. Se below a small test-site to do that (but readning fails): I use the function Test_Read for reading the value from the dynamic create text-field "txtName". I thanks...
11
4097
beacon
by: beacon | last post by:
Hi everybody, I created a database that links one table from an ODBC data source. I saved my password and UID to the data source so neither myself nor anyone else would have to login each time (that's just bonus background info). I take this table, which is read-only, and run an APPEND query that adds new items from the table into another table I created (that has two additional fields that will be updated by the user via a form). I also...
0
9497
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 synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10363
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. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10110
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8993
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 launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7517
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 instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6749
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 into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5534
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4067
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 we have to send another system
2
3670
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.