This is a discussion on How to Accessing Elements using javascript? within the HTML, CSS and Javascript Coding Techniques forums, part of the Web Development category; Hi all... How to Accessing Elements using javascript? Thanks......
| |||||||
| Register | FAQ | Members List | Calendar | Mark Forums Read |
|
#1
| |||
| |||
| Hi all... How to Accessing Elements using javascript? Thanks... |
|
#2
| |||
| |||
| Hi all... To do something interesting with HTML elements, we must first be able to uniquely identify which element we want. In the example <body> <form action=""> <input type="button" id="useless" name="mybutton" value="doNothing" /> </form> </body> We can use the "getElementById" method (which is generally preferred) document.getElementById("useless").style.color = "red"; or we can use the older hierarchical navigation method, document.forms[0].mybutton.style.color = "blue"; Notice that this uses the "name" attribute of the element to locate it. # Example of Accessing Elements in a DOM. <script type="text/javascript" > function showStatus() { var selectWidget = document.forms.beerForm.elements["beer"]; var myValue = selectWidget.options[selectWidget.selectedIndex].value; alert('You drank a \"'+ myValue +"\""); return true; } </script> <form name="beerForm" action=""> <select name="beer"> <option selected="selected">Select Beer</option> <option>Heineken</option> <option>Amstel Light</option> <option>Corona</option> <option>Corona Light</option> <option>Tecate</option> </select> <input type="button" name="submitbutton" value="Drink" onclick="showStatus()" /> </form> Thanks... |
![]() |
| Thread Tools | |
| Display Modes | |
| |
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Accessing local file system in Flash | Karpagarajan | Flash Actionscript Programming | 2 | 08-05-2008 02:45 AM |
| Accessing control in other page. | Kirubhananth | ASP and ASP.NET Programming | 2 | 04-01-2008 03:01 AM |
| WM 6 emulator not accessing web projects on my machine :( | theone | Windows Mobile | 1 | 07-27-2007 04:45 AM |
| Accessing COM component using java script | oxygen | HTML, CSS and Javascript Coding Techniques | 1 | 07-18-2007 01:25 AM |
| Accessing SQL server Database using java script | oxygen | HTML, CSS and Javascript Coding Techniques | 0 | 07-16-2007 11:09 PM |
Our Partners |