Forum Moderators: open
I have here a small function:-
function doStuff(){
var myapplet = document.getElementById('appletthing');
var keyselection = document.getElementById('myselect');
var keyvalue = keyselection.options[keyselection.selectedIndex];
alert("Doing thing ("+keyvalue.value+")");myapplet.doYourThing(keyvalue.value);
return false;
}
The idea is that I take a value from an HTML form select box and send it off as a string to this applets doYourThing function.
The select looks like:-
<select id="myselect">
<option value="1">Option 1</option>
<option value="2">Option 2</option>
<option value="3">Option 3</option>
</select>
I put the "alert" dialogue in the JS function to assist debugging, but it doesn't actually get that far.
Am I doing something silly ?
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Test SELECT Element Value</title>
</head>
<body>
<form action="">
<div>
<select id="myselect">
<option value="1">Option 1</option>
<option value="2">Option 2</option>
<option value="3">Option 3</option>
</select>
<input type="button" id="test" value="Test">
</div>
</form>
<script type="text/javascript">
function doStuff(){
var myapplet = document.getElementById('appletthing');
var keyselection = document.getElementById('myselect');
var keyvalue = keyselection.options[keyselection.selectedIndex];
alert("Doing thing ("+keyvalue.value+")");
return false;
}
var elTest = document.getElementById('test');
elTest.onclick = doStuff;
</script>
</body>
</html>
Strange thing is, Fotimans version works fine, mine doesn't.
Only difference appears to be that I'm setting the onClick in the element itself, Fotiman is setting it with JS.
Haven't got time at the moment to get an understanding of the difference but will try to get around at looking at that later.