options.value not working in Firefox

G

grpramodkumar

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,
 
S

scripts.contact

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;
 
A

ASM

(e-mail address 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;
}
 
V

Vicente Raúl Plata Fonseca [XnT]

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.value = value;
}

Would you please be more specific about your requirement?
 
S

scripts.contact

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



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

RobG

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;

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.
 
V

Vicente Raúl Plata Fonseca [XnT]

scripts.contact said:
Vicente said:
function change(value, sub)
{
var subCat = document.getElementById(sub);
var childArray = subCat.childNodes;
for(i = 0; i < childArray.length; i++)
childArray.value = value;
}



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

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

ASM

Vicente Raúl Plata Fonseca [XnT] a écrit :
scripts.contact said:
Vicente said:
function change(value, sub)
{
var subCat = document.getElementById(sub);
var childArray = subCat.childNodes;
for(i = 0; i < childArray.length; i++)
childArray.value = value;
}


function change(value, sub)
{
var subCat = document.getElementById(sub);
for(var i = 0; i < subCat.options.length; i++)
subCat.options.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 ?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,007
Latest member
obedient dusk

Latest Threads

Top