Accessing fields in the DOM

O

Otto Wyss

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
 
E

Evertjan.

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"?
 
O

Otto Wyss

Evertjan. said:
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?
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
 
E

Evertjan.

Otto Wyss wrote on 12 mrt 2007 in comp.lang.javascript:
Evertjan. said:
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)'
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]
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,995
Messages
2,570,231
Members
46,820
Latest member
GilbertoA5

Latest Threads

Top