Not able to see length in another function
- From: Kevin Old <kevinold (at) gmail.com>
- Date: Sun, 12 Feb 2006 23:48:09 -0500
Hello everyone,
I have the following code that builds <option> into a <select>.
buildModel() is called first, then setModel().
For some reason, I can't get the length of the "model" options in
setModel(), but can after they are built in buildModel();
function buildModel(originalRequest, json) {
var model = $('model');
//might need to clear options
//model.options.length = 0;
$H(json).each(function(node){
model.options[model.options.length] = new Option(node[0], node[1]);
});
alert(model.options.length); // alerts the proper length
}
function setModel(smodel) {
var model = $('model');
alert("inside setModel length is: " + model.options.length);
//length is zero
for (var i=0, len=model.options.length; i<len; ++i) {
if (model.options[i].value == smodel) {
model.selectedIndex = i;
}
}
}
Any ideas what could be causing this?
Thanks for any help,
Kevin
--
Kevin Old
kevinold (at) gmail.com
_______________________________________________
Rails-spinoffs mailing list
Rails-spinoffs (at) lists.rubyonrails.org
http://lists.rubyonrails.org/mailman/listinfo/rails-spinoffs