TalkPHP

TalkPHP (http://www.talkphp.com/forums.php)
-   Javascript, AJAX, E4X (http://www.talkphp.com/javascript-ajax-e4x/)
-   -   newb in javascript need help (http://www.talkphp.com/javascript-ajax-e4x/2819-newb-javascript-need-help.html)

sarmenhb 05-18-2008 06:54 PM

newb in javascript need help
 
hi, im doing this from a book and its not working what am i doing wrong?

here is my code
when i click on the first or second button i get this error

getvalue() is not defined

or

getValueTagName is not defined
onclick(click clientX=0, clientY=0)


Code:

<html>
<head>
<script type="text/javascript">

function getValueID() {

var byid = document.getElementById("listitems");
alert(byid[1]); //displays undefined
alert(byid.innerHTML); //displays all of ul's li items
alert(byid.parentNode); // parent node
alert(byid.childNotes[2];// shows second li item
alert(byid.firstChild); // shows first li
alert(byid.lastChild);// shows last li
alert(byid.nextSibling);
alert(byid.lastSibling);

}

function getValueTagName() {

var bytag = document.getElementByTagName("li");
alert(bytag[1]);


}

function getattrib() {

var link = document.getElementbyId("listitems");
alert(link.getAttribute("link");


}

</script>
</head>
<body>
<a href="http://google.com" id="link">google</a><br>

<ul id="listitems">
<li>first</li>
<li>second</li>
<li>third</li>
</ul>

<input type="submit" value="getValueID" onclick="getValueID()"/><br>
<input type="submit" value="getValueTagName" onclick="getValueTagName()"/><br>
<input type="submit" value="getAttribute" onclick="getattrib()"/><br>



</body>
</html>


Ken 05-18-2008 09:24 PM

Missing the closing parentheses after
Code:

alert(byid.childNotes[2]);// shows second li item
and
Code:

alert(link.getAttribute("link");
Try using Firebug when you're running these programs - it catches simple errors like this.

Also -
In document.getElementsByTagName you need to have Elements not Element.

byid.childNodes instead of byid.childNotes

document.getElementById with a capital B


All times are GMT. The time now is 01:03 AM.

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0