Accessing fields in the DOM

Discussion in 'Javascript' started by Otto Wyss, Mar 12, 2007.

  1. Otto Wyss

    Otto Wyss Guest

    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
     
    Otto Wyss, Mar 12, 2007
    #1
    1. Advertising

  2. Otto Wyss

    Evertjan. Guest

    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)
     
    Evertjan., Mar 12, 2007
    #2
    1. Advertising

  3. Otto Wyss

    Otto Wyss Guest

    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
     
    Otto Wyss, Mar 12, 2007
    #3
  4. Otto Wyss

    Evertjan. Guest

    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)
     
    Evertjan., Mar 12, 2007
    #4
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. call_me_anything
    Replies:
    4
    Views:
    473
    Pete Becker
    Sep 30, 2007
  2. Cyril.Liu
    Replies:
    0
    Views:
    459
    Cyril.Liu
    Dec 2, 2008
  3. middletree

    how to copy from fields to other fields

    middletree, Nov 5, 2003, in forum: ASP General
    Replies:
    1
    Views:
    173
    middletree
    Nov 5, 2003
  4. Replies:
    0
    Views:
    300
  5. AMT2K5
    Replies:
    1
    Views:
    206
    Eric Schwartz
    Nov 8, 2005
Loading...

Share This Page