Likewise with the array of forms in the page.. Some folks prefer using the
document.myform.myelement
syntax.
But you can use the element name also.
Cheers Mark
On Monday, October 20, 2003, at 03:14 PM, Jeff Kyser wrote:
form.elements is an array, and you'd have to specify it by index:
s = form.elements[i];
where i was a supplied integer in the range 0..form.elements.length-1, or
s = form.optionName;
if 'optionName' was a valid name for a form element.
HTH,
-jeff
On Monday, October 20, 2003, at 08:55 AM, 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]
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]

