You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Mark Lowe <ma...@talk21.com> on 2003/10/20 10:04:08 UTC

[ot] Re: question on javascript...

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<s.options.length; 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" <MK...@aquent.com> 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: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org


Re: [ot] Re: question on javascript...

Posted by Mark Lowe <ma...@talk21.com>.
Its been a while..

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 <ma...@talk21.com> 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: struts-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: struts-user-help@jakarta.apache.org
>
>
>
> ---------------------------------
> Do you Yahoo!?
> The New Yahoo! Shopping - with improved product search


---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org


Re: [ot] Re: question on javascript... [solved]

Posted by Jacob Wilson <st...@yahoo.com>.
Just tested this... It works Mark... I think I was missing 'document'... Thanks for the help and suggestions...
 
<HTML>
<BODY onLoad='initTable("table2");'>
<script language="javascript">
function getValue(optionName, hiddenValue) {
 var s = document.frmTest.elements[optionName];
 for (var i=0; i<s.options.length; i++) { 
  if (s.options[i].value == hiddenValue) {
   s.options[i].selected = true; 
   break;
  }
 } 
}
</script>
<form name="frmTest">
<input type="radio" onclick="getValue('abc','Mark')">
<br>
<select name="abc">
 <option value="Joe">Joe</option>
 <option value="Joseph">Joseph</option>
 <option value="Jacob">Jacob</option>
 <option value="Mark">Mark</option>
</select>
</form>
</BODY>
</HTML>

Mark Lowe <ma...@talk21.com> wrote:
I was on the wrong lines anyhow..

forms[] and elements[] deal with the index and/or the names. options[] 
requires the index.

the value is a property of the element not the option (at least i 
recall things being like that.

I'd just pass the value of the element as an argument But my apologies 
from not reading the question properly in the first place.

Cheers Mark

On Monday, October 20, 2003, at 03:38 PM, Jacob Wilson wrote:

>
> I get that error when I pass the element name only !!
>
> 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;
> }
> }
> }
>
>
> optionName is the element name and the error "elements.optionName is 
> not null or an object" when I try to use s.options.length...
>
>
> Mark Lowe wrote:
> You can specify an index or the name of the element.
>
> 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 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: struts-user-unsubscribe@jakarta.apache.org
>>> For additional commands, e-mail: struts-user-help@jakarta.apache.org
>>>
>>>
>>>
>>> ---------------------------------
>>> Do you Yahoo!?
>>> The New Yahoo! Shopping - with improved product search
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
>> For additional commands, e-mail: struts-user-help@jakarta.apache.org
>>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: struts-user-help@jakarta.apache.org
>
>
> ---------------------------------
> Do you Yahoo!?
> The New Yahoo! Shopping - with improved product search


---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org


---------------------------------
Do you Yahoo!?
The New Yahoo! Shopping - with improved product search

Re: [ot] Re: question on javascript...

Posted by Mark Lowe <ma...@talk21.com>.
I was on the wrong lines anyhow..

forms[] and elements[] deal with the index and/or the names. options[] 
requires the index.

the value is a property of the element not the option (at least i 
recall things being like that.

I'd just pass the value of the element as an argument But my apologies 
from not reading the question properly in the first place.

Cheers Mark

On Monday, October 20, 2003, at 03:38 PM, Jacob Wilson wrote:

>
> I get that error when I pass the element name only !!
>
> 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;
>  }
>  }
>  }
>
>
> optionName is the element name and the error "elements.optionName is 
> not null or an object" when I try to use s.options.length...
>
>
> Mark Lowe <ma...@talk21.com> wrote:
> You can specify an index or the name of the element.
>
> 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 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: struts-user-unsubscribe@jakarta.apache.org
>>> For additional commands, e-mail: struts-user-help@jakarta.apache.org
>>>
>>>
>>>
>>> ---------------------------------
>>> Do you Yahoo!?
>>> The New Yahoo! Shopping - with improved product search
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
>> For additional commands, e-mail: struts-user-help@jakarta.apache.org
>>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: struts-user-help@jakarta.apache.org
>
>
> ---------------------------------
> Do you Yahoo!?
> The New Yahoo! Shopping - with improved product search


---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org


Re: [ot] Re: question on javascript...

Posted by Jacob Wilson <st...@yahoo.com>.
I get that error when I pass the element name only !! 
 
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;
 }
 }
 }

 
optionName is the element name and the error "elements.optionName is not null or an object" when I try to use s.options.length...


Mark Lowe <ma...@talk21.com> wrote:
You can specify an index or the name of the element.

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 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: struts-user-unsubscribe@jakarta.apache.org
>> For additional commands, e-mail: struts-user-help@jakarta.apache.org
>>
>>
>>
>> ---------------------------------
>> Do you Yahoo!?
>> The New Yahoo! Shopping - with improved product search
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: struts-user-help@jakarta.apache.org
>


---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org


---------------------------------
Do you Yahoo!?
The New Yahoo! Shopping - with improved product search

Re: [ot] Re: question on javascript...

Posted by Mark Lowe <ma...@talk21.com>.
You can specify an index or the name of the element.

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 <ma...@talk21.com> 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: struts-user-unsubscribe@jakarta.apache.org
>> For additional commands, e-mail: struts-user-help@jakarta.apache.org
>>
>>
>>
>> ---------------------------------
>> Do you Yahoo!?
>> The New Yahoo! Shopping - with improved product search
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: struts-user-help@jakarta.apache.org
>


---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org


Re: [ot] Re: question on javascript...

Posted by Jeff Kyser <kt...@comcast.net>.
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 <ma...@talk21.com> 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: struts-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: struts-user-help@jakarta.apache.org
>
>
>
> ---------------------------------
> Do you Yahoo!?
> The New Yahoo! Shopping - with improved product search


---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org


Re: [ot] Re: question on javascript...

Posted by Jacob Wilson <st...@yahoo.com>.
Thanks for the help Mark... when I do this, it says elements.optionName is not null or an object... Any clue??? Thanks!

Mark Lowe <ma...@talk21.com> 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: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org



---------------------------------
Do you Yahoo!?
The New Yahoo! Shopping - with improved product search