I've got the following function that has me stumped. I'm pretty sure this is a simple problem, but I can't find a solution for it. Function: function selectit(formname,listname,num_options,val) { if(val == '') { return null; } else { for(i=0; i<num_options; i++) { if(document.formname.listname.options[i].value==val) { document.formname.listname.options[i].selected="selected"; } } } } Code (markup): Calling the function by: <script> selectit("form1","category",3,'cat_value'); </script> Code (markup): The error that I'm getting is "document.formname has no properties." If I manually access the list: alert(document.form1.category.option[0].value); I get the correct value back. Also, if I alert formname and/or listname, I get the excpected values back. Any help will be greatly appreciated. Thanks,
I actually ended up finding the solution. Instead of document.formname.listname.options Code (markup): It needed to be: document.forms[formname].elements[listname].options Code (markup): Hope this helps someone else with the same problem.
Use window.forms for a cross-browser solution. Better yet avoid forms altogether, they are a clumsy and well outdated solution.