PDA

View Full Version : troubleshoot this code?



evan
05-05-2009, 07:42 PM
:mad:
I don't know what I'm doing wrong here can anyone take a look?



<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/stict.dtd">

<html>
<head>

<title>first form example2</title>



<script type="text/javascript">



function displayvalue(){
var selected = document.forms["starform"].startype.value;

alert("You selected " + selected);
}


</script></head>
<body>

<form id="starform" action ="" onsubmit="return false;">

Select a constellation:

<select onchange="displayvalue() name="startype">

<option selected="selected"></option>

<option value= "a">a</option>
<option value= "b">b</option>
<option value= "c">c</option>

</select>
</form>

</body>
</html>

Nile
05-05-2009, 11:08 PM
Here, this should work:


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/stict.dtd">

<html>
<head>
<title>first form example2</title>
<script type="text/javascript">
function displayvalue(me){
alert("You selected "+me.value);
}
</script>
</head>
<body>
<form id="starform" onsubmit="return false;">
Select a constellation:
<select onchange="displayvalue(this);" name="startype">
<option selected="selected"></option>
<option value="a">a</option>
<option value="b">b</option>
<option value="c">c</option>
</select>
</form>
</body>
</html>

Although I completely changed you're javascript to more effecient like js, you can just change this line (in your script):


<select onchange="displayvalue() name="startype">

To this:


<select onchange="displayvalue()" name="startype">