• Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint
Share this Page URL
Help

Chapter 6. Using Core HTML Methods and Events > JavaScript’s Core HTML Methods

JavaScript’s Core HTML Methods

We’ve already seen some of the core HTML methods at work, such as the getElementsByTagName method, which returns an array of elements based with the same tag name. Here’s an example we saw in Chapter 4, “Handling the Browser Environment”:

(Listing 04-11.html on the web site)

<HTML> 
    <HEAD> 
        <TITLE> 
            Accessing HTML Elements 
        </TITLE> 
        <SCRIPT LANGUAGE="JavaScript"> 
            <!--
            function getText() 
            { 
                if(navigator.appName == "Netscape") { 
                alert("document.form1.text1.value = " + document.form1.text1.value)  
                alert("document.forms[0].text1.value = " + document.forms[0].text1.value) 
                alert("document.getElementsByName(\"text1\")[0].value = " 
                    + document.getElementsByName("text1")[0].value) 
                alert(“document.getElementsByTagName(\"INPUT\")[0].value = "
					+ document.getElementsByTagName("INPUT")[0].value) 
                } 

                if (navigator.appName == "Microsoft Internet Explorer") { 
                alert("document.form1.text1.value = " + document.form1.text1.value) 
                alert("document.forms[0].text1.value = " 
                    + document.forms[0].text1.value) 
                alert("document.all.text1.value = " 
                      + document.all.text1.value) 
                alert("document.all[\"text1\"].value = " 
                      + document.all["text1"].value) 
                alert("document.all.tags(\"INPUT\")[0].value = " 
                      + document.all.tags("INPUT")[0].value) 
                alert("document.getElementsByName(\"text1\")[0].value = " 
                    + document.getElementsByName("text1")[0].value) 
                alert("document.getElementsByTagName(\"INPUT\")[0].value = "
					+ document.getElementsByTagName("INPUT")[0].value) 
                } 
            } 
            // --> 
        </SCRIPT> 
    </HEAD> 

    <BODY> 
        <H1>Accessing HTML Elements</H1> 
        <FORM NAME="form1"> 
            <INPUT TYPE="TEXT" NAME="text1" ID="text1"> 
            <INPUT TYPE="BUTTON" VALUE="Click Me!" ONCLICK="getText()"> 
        </FORM> 
    </BODY> 
</HTML> 

					  


PREVIEW

                                                                          

Not a subscriber?

Start A Free Trial


  
  • Creative Edge
  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint