Programming Forums

Programming Forums (http://www.programmingforums.org/forumindex.php)
-   JavaScript and Client-Side Browser Scripting (http://www.programmingforums.org/forum23.html)
-   -   Ug Javascript Is Evil (http://www.programmingforums.org/showthread.php?t=747)

Berto Oct 5th, 2004 8:26 AM

:


<html>
<head>
<html>
<head>
<link href="theme/Master.css" rel="stylesheet" type="text/css" />
<script type="text/javascript">
 
function changeTxt(){
        document.write(document.all.secLvl.selectedIndex);
        if (document.all.secLvl.selectedIndex == "1"){
 document.all.test1.innerHTML = "rar this works";
        }else{
 document.all.test1.innerHTML = "nay it dont";
        }
}
</script>

</head>
<body>
<form name="test">
<select name="secLvl" width="5" onChange=changeTxt() >
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
</select>

<div id="test1">this is a test</span>

</form>

</body>
</html>


I want it so that when someone selects an option the text changes accordingly i had it working so the text changed but the comparison is not working and so therefore always gives teh second result instead of the first one when you go on the 1 option...

Ooble Oct 5th, 2004 1:54 PM

First of all, div tags end in </div>, not </span>. And instead of using document.all.blah, use document.getElementById("blah").

Berto Oct 6th, 2004 2:09 AM

fair enough i did know the end div tag thingy i was just being gay and tried to use span fiorst, but still i cant get the current value from the list box

Berto Oct 6th, 2004 6:56 AM

:


<html>
<head>
<html>
<head>
<link href="theme/Master.css" rel="stylesheet" type="text/css" />
<script LANGUAGE="JavaScript">
 
function changeTxt(){
       
        Item = document.test.MOO.selectedIndex;
        document.write(Item);
        if (Item == 0){
 document.getElementById("test1").innerHTML = "rar this works";
        }else{
 document.getElementById("test1").innerHTML = "nay it dont";
        }
}
</script>

</head>
<body>
<form name="test" action="" method="get">
<select name="MOO" width="5" onChange=changeTxt() >
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
</select>

<div id="test1">this is a test</div>

</form>


thats my javascript.html exactly as it is on the tin.

the error i am getting is

Line : 15
Char: 3
Error : 'document.getElementById(...)' is null or not an object
Code: 0
URL: about:blank

Ooble Oct 6th, 2004 10:51 AM

Then I have no idea - that code should work, apart from one thing - you have to define Item using var Item.


All times are GMT -5. The time now is 9:14 PM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC