try the index or hardcode the form name like before in case it doesn't like the form object being passed as an argument...
function getValue(formName,elementName,value) {
s = document.forms[formName].elements[elementName];
..Cheers Mark
On Monday, October 20, 2003, at 02:55 PM, Jacob Wilson wrote:
Thanks for the help Mark... when I do this, it says elements.optionName is not null or an object... Any clue??? Thanks!
Mark Lowe <[EMAIL PROTECTED]> wrote:Those variable don't really need to be global.
function getValue(form, optionName,hiddenValue) { s = form.elements[optionName]; for(i = 0;i < s.options.length;i++) { if(s.options[i].value == hiddenValue) { s.options[i].selected = true; break; } } }
onsomeformevent="getValue(this.form,'foo','bar')"
Cheers Mark
On Monday, October 20, 2003, at 07:55 AM, Jacob Wilson wrote:
Thanks Matt... It sure helped...
Actually, now, I tried to put it as a common function like...
function getValue(optionName, hiddenValue) { var s = document.forms[0].optionName; for (var i=0; i> if ( s.options[i].value == hiddenValue ) { s.options[i].selected = true; break; } } }
where optionName is the name of the selectboxes that r in the form -- when I try to use 'optionName' it throws an error when I try to get the length saying option is null... Am I missing something here???
Please let me know... Thanks in advance...
-Jacob
"Kruse, Matt" wrote:This is a basic question... Can I find the index of a select box, if I have the value or the text ??? document.formName.optionName.options["C"].selected=true -- This won't work!!
You need to loop through each option, checking to see it's value and then checking it.
var s = document.formname.optionname; for (var i=0; i if (s.options[i].value=="C") { s.selected=true; } }
Or, using functions at http://www.mattkruse.com/javascript/validations/ you can do:
setInputValue(document.formname.optionname,"C");
Be careful - multiple options are allowed to have the same value!
Matt Kruse
--------------------------------- Do you Yahoo!? The New Yahoo! Shopping - with improved product search
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
--------------------------------- Do you Yahoo!? The New Yahoo! Shopping - with improved product search
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]

