IT Community - Software Programming, Web Development and Technical Support

How to Accessing Elements using javascript?

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......


Go Back   IT Community - Software Programming, Web Development and Technical Support > Web Development > HTML, CSS and Javascript Coding Techniques

Register FAQ Members List Calendar Mark Forums Read
  #1  
Old 10-24-2007, 07:18 AM
itbarota itbarota is offline
D-Web Architect
 
Join Date: Jun 2007
Posts: 542
itbarota is on a distinguished road
Default How to Accessing Elements using javascript?

Hi all...

How to Accessing Elements using javascript?


Thanks...
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2  
Old 10-24-2007, 07:21 AM
Pvinothkumar Pvinothkumar is offline
D-Web Analyst
 
Join Date: Sep 2007
Posts: 235
Pvinothkumar is on a distinguished road
Default Re: How to Accessing Elements using javascript?

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...
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off

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


All times are GMT -7. The time now is 06:58 PM.


Copyright ©2004 - 2007, DiscussWeb. All Rights Reserved.
Our Partners
One Way Moving Companies | Stamford Dentist | Euro Millions Lottery | Home Loans| Furniture

SEO by vBSEO 3.0.0