Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Javascript > options.value not working in Firefox

Reply
Thread Tools

options.value not working in Firefox

 
 
grpramodkumar@gmail.com
Guest
Posts: n/a
 
      05-07-2007
HI,


function change(value,sub) {
subcat = document.getElementById(sub);
subcat.options.value = value;

}


<select id="aa">
<option value="1">one</option>
<option value="2">two</option>
</select>

<input type="button" value="Click" onclick="change(2,'aa');">


I am trying to change the value of a select box dynamicaly on click ,
the above code is working in IE , but not in firefox,

Thanks,

 
Reply With Quote
 
 
 
 
scripts.contact
Guest
Posts: n/a
 
      05-07-2007
On May 7, 5:18 am, (E-Mail Removed) wrote:
> HI,
>
> function change(value,sub) {
> subcat = document.getElementById(sub);
> subcat.options.value = value;
>
> }
>
> <select id="aa">
> <option value="1">one</option>
> <option value="2">two</option>
> </select>
>
> <input type="button" value="Click" onclick="change(2,'aa');">
>
> I am trying to change the value of a select box dynamicaly on click ,
> the above code is working in IE , but not in firefox,
>


subcat.value = value;

 
Reply With Quote
 
 
 
 
ASM
Guest
Posts: n/a
 
      05-07-2007
http://www.velocityreviews.com/forums/(E-Mail Removed) a écrit :
>
> function change(value,sub) {
> subcat = document.getElementById(sub);
> subcat.options.value = value;
> }
>
> <select id="aa">
> <option value="1">one</option>
> <option value="2">two</option>
> </select>
>
> <input type="button" value="Click" onclick="change(2,'aa');">
>
>
> I am trying to change the value of a select box dynamicaly on click ,
> the above code is working in IE , but not in firefox,


I do not understand the value of what you try to change
nor what you give it as replacement ... ?

If you want the drop down selector reflects the choice 2 :

<button onclick="change(2, 'aa');">show item 2</button>


function change(option, sub) {
document.getElementById(sub).selectedIndex = --option;
}


--
Stephane Moriaux et son (moins) vieux Mac déjà dépassé
 
Reply With Quote
 
Vicente Raúl Plata Fonseca [XnT]
Guest
Posts: n/a
 
      05-07-2007
On May 7, 6:18 am, (E-Mail Removed) wrote:
> HI,
>
> function change(value,sub) {
> subcat = document.getElementById(sub);
> subcat.options.value = value;
>
> }
>
> <select id="aa">
> <option value="1">one</option>
> <option value="2">two</option>
> </select>
>
> <input type="button" value="Click" onclick="change(2,'aa');">
>
> I am trying to change the value of a select box dynamicaly on click ,
> the above code is working in IE , but not in firefox,
>
> Thanks,


I don't get it at all... You want ALL the options to have the same
value as specified in the 1st parameter of the function??

Then this workaround is 100% surely will work in both Firefox,
Explorer and Konqueror ( I've tested it ).

function change(value, sub)
{
var subCat = document.getElementById(sub);
var childArray = subCat.childNodes;
for(i = 0; i < childArray.length; i++)
childArray[i].value = value;
}

Would you please be more specific about your requirement?

 
Reply With Quote
 
scripts.contact
Guest
Posts: n/a
 
      05-07-2007
Vicente Raúl Plata Fonseca [XnT] wrote:

> function change(value, sub)
> {
> var subCat = document.getElementById(sub);
> var childArray = subCat.childNodes;
> for(i = 0; i < childArray.length; i++)
> childArray[i].value = value;
> }



function change(value, sub)
{
var subCat = document.getElementById(sub);
for(var i = 0; i < subCat.options.length; i++)
subCat.options[i].value = value;
}

 
Reply With Quote
 
RobG
Guest
Posts: n/a
 
      05-08-2007
On May 7, 9:18 pm, (E-Mail Removed) wrote:
> HI,
>
> function change(value,sub) {
> subcat = document.getElementById(sub);


There doesn't seem to be any reason for subcat to be global, so keep
it local with var:

var subcat = ...


> subcat.options.value = value;


subcat.options is an HTML Collection, it doesn't have a value property
specified in the W3C specification. What happens when you set it is
likely browser dependent - as you've discovered.


> }
> <select id="aa">
> <option value="1">one</option>
> <option value="2">two</option>
> </select>
> <input type="button" value="Click" onclick="change(2,'aa');">
>
> I am trying to change the value of a select box dynamicaly on click ,


The value of a select *element* is based on the selected option. To
change the selected option, change the select element's
selectedIndex. The index is zero based, so to select the second
option:

subcat.selectedIndex = 1;

<URL: http://www.w3.org/TR/DOM-Level-2-HTML/html.html#ID-85676760>


> the above code is working in IE , but not in firefox,


It's always good to explain either what "working" or "not working" (or
both) means.


--
Rob

 
Reply With Quote
 
Vicente Raúl Plata Fonseca [XnT]
Guest
Posts: n/a
 
      05-08-2007
scripts.contact wrote:
> Vicente Raúl Plata Fonseca [XnT] wrote:
>
> > function change(value, sub)
> > {
> > var subCat = document.getElementById(sub);
> > var childArray = subCat.childNodes;
> > for(i = 0; i < childArray.length; i++)
> > childArray[i].value = value;
> > }

>
>
> function change(value, sub)
> {
> var subCat = document.getElementById(sub);
> for(var i = 0; i < subCat.options.length; i++)
> subCat.options[i].value = value;
> }

Not W3C compliant. DOM objects otherwise are. That's why the script
doesn't load in Firefox.

 
Reply With Quote
 
ASM
Guest
Posts: n/a
 
      05-08-2007
Vicente Raúl Plata Fonseca [XnT] a écrit :
> scripts.contact wrote:
>> Vicente Raúl Plata Fonseca [XnT] wrote:
>>
>>> function change(value, sub)
>>> {
>>> var subCat = document.getElementById(sub);
>>> var childArray = subCat.childNodes;
>>> for(i = 0; i < childArray.length; i++)
>>> childArray[i].value = value;
>>> }

>>
>> function change(value, sub)
>> {
>> var subCat = document.getElementById(sub);
>> for(var i = 0; i < subCat.options.length; i++)
>> subCat.options[i].value = value;
>> }

> Not W3C compliant. DOM objects otherwise are. That's why the script
> doesn't load in Firefox.
>


first time I hear that a not compliant W3C could break a JS ... !
(both functions above work fine, and 2nd is better)

What say you it is not W3C compliant ?

--
Stephane Moriaux et son (moins) vieux Mac déjà dépassé
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
FIrefox wants top open images in app, not in firefox Evan Platt Computer Support 6 11-17-2008 04:30 AM
Help: Javascript not working in Firefox "event not defined" Wiseman Javascript 1 07-25-2008 03:04 PM
script not working in Firefox (variable is not defined) ORF3O Javascript 2 10-14-2005 11:14 AM
wifi not working on new hp, or not working after live update =?Utf-8?B?RHJhZ29ueA==?= Wireless Networking 1 10-01-2005 11:17 PM
Yahoo! Toolbar Beta for Firefox - Not Compatible with Firefox 1.0.2? NA Firefox 6 04-02-2005 06:13 PM



Advertisments