PDA

View Full Version : document.form.options.value in mozilla



mahoni
12-13-2006, 11:11 AM
hello, first of all i have to say that iam spanish and my english is not so good...

well, i want to change the value of a select option:

window.document.formulario.minuto.options.value="23";
window.document.formulario.hora.options.value="50";
window.document.formulario.eguna.options.value="Atzo";

this is my code, in internet explorer works fine, but in mozilla not!
i have tried with getElementById, setElementById(i donot know if it exists),...

so i want to change the value when i push a button, but in mozilla is imposible.
thanks for all.

Twey
12-13-2006, 01:20 PM
Firstly, you should access it as, for example, document.forms.formulario.elements.minuto. Secondly, options is a collection, and doesn't, as far as I know, have a value property. Use the element's selectedIndex property instead:
window.document.forms.formulario.elements.minuto.selectedIndex = 2;

mwinter
12-13-2006, 02:36 PM
Secondly, options is a collection, and doesn't, as far as I know, have a value property.

You're right: it doesn't. The select element itself does, though ancient browsers (such as NN4) don't implement it.



window.document.forms.formulario.elements.minuto.selectedIndex = 2;

Omit the "window." member expression. Referencing the global object directly would only be necessary if the first encountered identifier, document, in the scope chain doesn't refer to the document object. That should only happen if a variable with the same identifier is declared in some function.

Mike

jscheuer1
12-14-2006, 07:21 AM
window.document.forms.formulario.elements.minuto.selectedIndex = 2;

will change the selected index of the form but not the value of any of its options. I'm confused because IE, with additions, understands Spanish for certain code applications so:

document.forms

and:

document.formulario

may be equivalent, making this even more of mystery to me.



mahoni,

Can you show us what your form and options tags (your HTML code) look like?

mahoni
12-14-2006, 07:38 AM
Thank you all for your answers.I have tried selectedIndex, but it doesnt work.Formulario is the name of the form.Here is my html code:

<form name="formulario" id="menu123">

<select name="hora" size=1 id="prueba123">
<option selected value="00">00 </option>
<option value="01">01 </option>
<option value="02">02 </option>
<option value="03">03 </option>
<option value="04">04 </option>
<option value="05">05 </option>
<option value="06">06 </option>
<option value="07">07 </option>
<option value="08">08 </option>
<option value="09">09 </option>
<option value="10">10 </option>
<option value="11">11 </option>
<option value="12">12 </option>
<option value="13">13 </option>
<option value="14">14 </option>
<option value="15">15 </option>
<option value="16">16 </option>
<option value="17">17 </option>
<option value="18">18 </option>
<option value="19">19 </option>
<option value="20">20 </option>
<option value="21">21 </option>
<option value="22">22 </option>
<option value="23">23 </option> </select>

<select name="minuto" size=1>
<option selected value="00">00 </option>
<option value="10">10 </option>
<option value="20">20 </option>
<option value="30">30 </option>
<option value="40">40 </option>
<option value="50">50 </option>
</select></font>
</b>


<img src="../imagenes/flechas1.gif" name="ATRAS" onClick="ChangeImage(-1)">

<img src="../imagenes/flechas.gif" name="ALANTE" onClick="ChangeImage(1)">

</td>
</tr>



<tr>
<th class="fecha" colspan="3">Eguna/D&#237;a</th>
</tr>
<tr>
<td>

<select name="eguna" size=1>
<option selected="selected" VALUE="Gaur"><%=gaur%></option>
<option value="Atzo"><%=atzo%></option>

</select>

jscheuer1
12-14-2006, 08:08 AM
Try this out:


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/1999/REC-html401-19991224/loose.dtd">
<html>
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<script type="text/javascript">
function testit(){
document.forms.formulario.hora.selectedIndex=23;
document.forms.formulario.minuto.selectedIndex=5;
document.forms.formulario.eguna.selectedIndex=1;
}
</script>
</head>
<body>
<form name="formulario" id="menu123">

<select name="hora" size=1 id="prueba123">
<option selected value="00">00 </option>
<option value="01">01 </option>
<option value="02">02 </option>
<option value="03">03 </option>
<option value="04">04 </option>
<option value="05">05 </option>
<option value="06">06 </option>
<option value="07">07 </option>
<option value="08">08 </option>
<option value="09">09 </option>
<option value="10">10 </option>
<option value="11">11 </option>
<option value="12">12 </option>
<option value="13">13 </option>
<option value="14">14 </option>
<option value="15">15 </option>
<option value="16">16 </option>
<option value="17">17 </option>
<option value="18">18 </option>
<option value="19">19 </option>
<option value="20">20 </option>
<option value="21">21 </option>
<option value="22">22 </option>
<option value="23">23 </option> </select>

<select name="minuto" size=1>
<option selected value="00">00 </option>
<option value="10">10 </option>
<option value="20">20 </option>
<option value="30">30 </option>
<option value="40">40 </option>
<option value="50">50 </option>
</select>
</b>


<img src="../imagenes/flechas1.gif" name="ATRAS" onClick="ChangeImage(-1)">

<img src="../imagenes/flechas.gif" name="ALANTE" onClick="ChangeImage(1)">

</td>
</tr>



<tr>
<th class="fecha" colspan="3">Eguna/Día</th>
</tr>
<tr>
<td>

<select name="eguna" size=1>
<option selected="selected" VALUE="Gaur"><%=gaur%></option>
<option value="Atzo"><%=atzo%></option>

</select><br>
<input type="button" onclick="testit();" value="Test">
</form>
</body>
</html>

mahoni
12-27-2006, 11:57 AM
Thanks a lot!!!!
It`s all Ok now.

Fuc... differences between explorers!!!

jejeje.