Otto Wyss a écrit :
Thanks, albeit your using "getElementById" and not "getElementsByName".
I do not understand why you don't use forms tree ?!
function getSelectOptionChosen(form_name, select_name) {
var s = document.forms[form_name].elements[select_name];
if(s) return s.selectedIndex.value;
}
var sel = document.getElementsByName('name')[0];
it is not ('name') but (name)
Never give as name to an element : 'name'
still retuns error "sel has no properties".
Try giving an id to your select
and Pete's function would have to work
Pete wrote:
>function getSelectedIndex(label) {
retval = '';
var obj = document.getElementById(label);
if (obj) retval = obj.options[obj.selectedIndex].value;
return retval;
}
But ... I think you make an error somewhere in calling your function,
because your function works fine
Copy-paste following to test :
<html>
<head>
<title>get element by name</title>
<script type="text/javascript">
function getSelectValue (name) {
var sel = document.getElementsByName(name)[0];
var i = sel.options.selectedIndex;
return i == -1? "": sel.options[i].value;
}
</script>
</head>
<body>
<a href="#" onclick="alert(getSelectValue('truc'));return false;">
what?
</a>
<form>
<select name="truc">
<option>
choice
</option>
<option value="01">
case 1
</option>
<option value="02">
case 2
</option>
<option value="03">
case 3
</option>
</select>
</form>
</body>
</html>
--
Stephane Moriaux et son (moins) vieux Mac déjà dépassé
Stephane Moriaux and his (less) old Mac already out of date