Hi all,
I have a function that takes an array as a parameter and assigns the names/values in that array to the [I]options [I]select
Ideally, I would make that function a method of the [I]Select.prototype[I]Object.prototype[I]prefer [I]Select.prototype
Question:
There is NO constructor for the [I]Select[I]why[I]Select
[CODE]<html>
<head>
<title>Test</title>
<script type=”text/javascript”>
var newOpts = [
{name:”dog”,value:”lazy”},
{name:”cat”,value:”smug”},
{name:”fish”,value:”boring”}];
function setOpts( a ) {
if ( this.type.match(/^select/i) )
{
var a = arguments[0];
this.options.length = 0;
for ( var i=0; i < a.length; i++ )
{
this.options[i] = new Option(a[i].name, a[i].value);
}
}
}
// Does NOT work
//Select.prototype.setOptions = setOpts;
// Does work
Object.prototype.setOptions = setOpts;
</script>
</head>
<body>
<a href=”javascript:document.getElementById(‘oppy’).setOptions(newOpts);”>change select</a><br />
<form>
<select id=”oppy” name=”choice”>
<option value=”1″>one</option>
<option value=”2″>two</option>
<option value=”3″>three</option>
</select>
<input type=”submit” value=”submit” />
</form>
</body>
</html>