473,387 Members | 1,512 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,387 software developers and data experts.

Accessing fields in the DOM

I always have trouble how I can access any field from the DOM with
Javascript, how to formulate the right syntax. E.g. I'd like to test if
a button in a form was clicked.

function test1 (t) {
var bnt = t....???
}
function test2 (t) {
var bnt = t....???
}
<form name="login" onsubmit=test1(this) ...
<table ...
<input type="submit" name="logon" ... onclick=test2(this)...

What's the right Javascript syntax to access the button in the onsubmit
case and the onclick case?

Is there a better tool than DomInspector (Mozilla) which is able to to
show a field in Javascript notation?

Is there a description on the web which explains how to access any field
with Javascript?

O. Wyss
--
Cross-platform applications:
http://wyoguide.sf.net/index.php?page=projectlist.php
Mar 12 '07 #1
3 1360
Otto Wyss wrote on 12 mrt 2007 in comp.lang.javascript:
I always have trouble how I can access any field from the DOM with
Javascript, how to formulate the right syntax. E.g. I'd like to test
if a button in a form was clicked.
function test1 (t) {
var bnt = t....???
}
function test2 (t) {
var bnt = t....???
}
<form name="login" onsubmit=test1(this) ...
<table ...
<input type="submit" name="logon" ...
onclick=test2(this)...

What's the right Javascript syntax
Any syntax that works cross browser is right, methinks.
to access the button in the onsubmit case
var bnt = t.elements['logon']
and the onclick case?
var bnt = t

Is there a better tool than DomInspector (Mozilla) which is able to to
show a field in Javascript notation?
What is "a field in Javascript notation"?
Is there a description on the web which explains how to access any
field with Javascript?

--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
Mar 12 '07 #2
Evertjan. wrote:
Otto Wyss wrote on 12 mrt 2007 in comp.lang.javascript:
>to access the button in the onsubmit case

var bnt = t.elements['logon']
>and the onclick case?

var bnt = t
And how do I find out if this element was clicked or not?
>
>Is there a better tool than DomInspector (Mozilla) which is able to to
show a field in Javascript notation?

What is "a field in Javascript notation"?
Any kind of element (button, input, select, etc) within any block
structure (form, table, div, etc).

O. Wyss
--
Cross-platform applications:
http://wyoguide.sf.net/index.php?page=projectlist.php
Mar 12 '07 #3
Otto Wyss wrote on 12 mrt 2007 in comp.lang.javascript:
Evertjan. wrote:
>Otto Wyss wrote on 12 mrt 2007 in comp.lang.javascript:
>>to access the button in the onsubmit case

var bnt = t.elements['logon']
>>and the onclick case?

var bnt = t
And how do I find out if this element was clicked or not?
onclick = 'alert("This element is clicked: " + this.name)'
>
>>
>>Is there a better tool than DomInspector (Mozilla) which is able to
to show a field in Javascript notation?

What is "a field in Javascript notation"?
Any kind of element (button, input, select, etc) within any block
structure (form, table, div, etc).
How could that be javascript?
What do you want the DOM inspector for?
DOM is good to find a parent,
but children are not always cross browser ligitimate.

Oh, do you mean a Javascript usable element pointer?

var myElement = document.getElementById('myElementId');

or if you want to use the parent name and the element's name,
using specific collections:

var myElement = document.forms['myForm'].elements['myelement']

or if you want to count elements by their position:

var myElement = document.forms['myForm'].elements[3]
var myElement = document.forms[0].elements[3]
--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
Mar 12 '07 #4

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

Similar topics

2
by: Darren Smith | last post by:
I am having a great deal of difficulty accessing individual fields generated from a Sql Server 7 view. When I specify the actual field name, I get the error: Microsoft OLE DB Provider for ODBC...
2
by: Evil | last post by:
This is likely a very simple question, but one which is leaving me a bit confused. i have an image control on a report in Access97 then in the Detail's ON FORMAT Event, i have: Private Sub...
2
by: CrazyAtlantaGuy | last post by:
I'm having a strange problem and I was hoping someone could give me some guidance. I am accessing a Microsoft SQL 2000 server through ASP scripts on our webserver. The sql server and web server...
2
by: Stu | last post by:
Hi, I am migrating a large app to .Net 2 and am having problems with accessing hidden fields using javascript. As I am using masterpages the control names are prefixed with the control...
14
by: johnsobd | last post by:
I am accessing an existing Foxpro database, of which I have no control over. I have been successful in accessing all the tables except for one. This one table I can access the first 9 fields in...
5
by: nomail.thanks | last post by:
I apologize for the question in advance. I have lots of experience with lots of other languages, but now I'm trying to accomplish something with VB.NET Express. My experience with VB.NET express...
5
by: TS | last post by:
is it preferred to access member variables directly in code, on the page that declared them, versus going thru a property accessor? I would think that since theres no security concerns or anything...
1
by: adamredwards | last post by:
I have a page with some form elements that are dynamically generated. They are inserted into the dom by first cloning a node, changing the values like name, and then inserted with insertBefore(). ...
7
by: Chuck Anderson | last post by:
I'm pretty much a JavaScript novice. I'm good at learning by example and changing those examples to suit my needs. That said .... ..... I have some select fields in a form I created for a...
19
by: cj | last post by:
I'm getting terrible response times trying to pull data from VFP tables using .net--like 2 minutes! Can someone help? f:\arcust01 currently contains 187,728 records and is indexed on CUSTNO...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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...

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.