www.webdeveloper.com
Results 1 to 6 of 6

Thread: javascript Document object model

  1. #1
    Join Date
    Nov 2013
    Location
    Matara
    Posts
    9

    Exclamation javascript Document object model

    please explain deeply about javascript Document object model.

  2. #2
    Join Date
    Dec 2013
    Posts
    21

  3. #3
    Join Date
    Nov 2013
    Location
    Matara
    Posts
    9
    please explain more..
    by examples.it will helpful me.

  4. #4
    Join Date
    Oct 2013
    Posts
    457
    There are many examples in the tutorial landar linked to. I quit counting at 33 over the course of at least 12 pages, and there may be more.

    A famous American author once said:
    "Those who can read and don't are no better off than those who can't."
    — Samuel Clemens (Mark Twain)

  5. #5
    Join Date
    Mar 2007
    Location
    localhost
    Posts
    2,290
    Depends on what you want to know...

    example here on accessing a form, this may help you understand about accessing some elements within a document

    document.formname.inputame.value will be the same as document.forms[0].inputname.value if document.formname is the first form on a web page as you can have more than one form on a document.

    accessing the form via its name is more human readable but if you have 3 or so forms and you want to know which form has the input then you would loop through them.

    Code:
    for(f=0; f<document.forms.length; f++)
        if( document.forms[f].inputname.value!="" ) ...
    that would check the field (input) called inputname on all forms on a single page whereas using the name of the form directly would require more code or individual references to the form name, eg

    Code:
    var formNames = ["f1","lists","address"];
    for(f=0; f< formNames.length; f++)
        if( document.forms[ formNames[f] ].inputname.value!="" ) ...
    Abbreviation... having to write document all the time can be time consuming and make code reading laborious, you can shorten the code you use by doing the following...

    Code:
    var d = document;
    for(f=0; f<d.forms.length; f++)
        if( d.forms[f].inputname.value!="" ) ...
    d will equal the entire document contents.

    Accessing DOM elements by its ID tag is very common, I personally frown upon it and it should only IMHO be used as a last resort to using the DOM properly, you can only have one unique ID on a web page. I am not saying that the document.getElementById shouldn't be used, it should be used when no alternative exists and the page content is build dynamically and the position in the DOM can't be guaranteed to be fixed where you have duplicate field names as forms can have duplicate name fields, eg...

    HTML Code:
    <form name="myForm" action="./"  >
        <input name="inputname" type="test" value="" >
        <input name="inputname" type="test" value="" >
        <input name="inputname" type="test" value="" >
        <input name="submit" type="submit" value="Submit" >
    </form>
    this would mean that the DOM takes on a new dimension

    document.formname.inputame[n].value where n is the value 0 to nth element in that array, in the above form example it would be 0,1 or 2 as you have 3 form input fields with the same inputname for the form name, this could be because that data is grouped like a personal address field.

    Only real suggestion is to try it and once you understand the workings of the HTML Form elements, you can then move on to other elements of the DOM and work with child and parent elements which is another level, you only really need to go as deep as you need to with DOM access, to try and learn it all can take time and you may find that you may only use it once or twice whereas accessing form elements will be the most common part of using DOM that you will meet, its worth knowing how that works first.
    Last edited by \\.\; 01-02-2014 at 08:10 AM.
    Yes, I know I'm about as subtle as being hit by a bus..(\\.\ Aug08)
    Yep... I say it like I see it, even if it is like a baseball bat in the nutz... (\\.\ Aug08)
    I want to leave this world the same way I came into it, Screaming, Incontinent & No memory!
    I laughed that hard I burst my colostomy bag... (\\.\ May03)
    Life for some is like a car accident... Mine is like a motorway pile up...

    Problems with Vista? :: Getting Cryptic wid it. :: The 'C' word! :: Whois?

  6. #6
    Join Date
    Nov 2013
    Location
    Matara
    Posts
    9
    thank you for kindly help me
    ..

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles