Go Back   Dynamic Drive Forums > General Coding > JavaScript
Search Dynamic Drive Forums:

Reply
 
Thread Tools Search this Thread
  #1  
Old 12-13-2006, 11:11 AM
mahoni mahoni is offline
Junior Coders
 
Join Date: Dec 2006
Location: Basque Country
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default document.form.options.value in mozilla

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.
Reply With Quote
  #2  
Old 12-13-2006, 01:20 PM
Twey's Avatar
Twey Twey is offline
Modtoreador
 
Join Date: Jun 2005
Location: 英国
Posts: 11,933
Thanks: 1
Thanked 180 Times in 172 Posts
Blog Entries: 2
Default

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:
Code:
window.document.forms.formulario.elements.minuto.selectedIndex = 2;
__________________
Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!
Reply With Quote
  #3  
Old 12-13-2006, 02:36 PM
mwinter mwinter is offline
Elite Coders
 
Join Date: Dec 2004
Location: UK
Posts: 2,361
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Quote:
Originally Posted by Twey View Post
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.

Quote:
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
Reply With Quote
  #4  
Old 12-14-2006, 07:21 AM
jscheuer1's Avatar
jscheuer1 jscheuer1 is offline
No Kidding?
 
Join Date: Mar 2005
Location: SE PA USA
Posts: 19,005
Thanks: 19
Thanked 1,135 Times in 1,121 Posts
Blog Entries: 3
Default

Quote:
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?
__________________
WWWWWWWWWWWW
- John
________________________

Really Show Your Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate
Reply With Quote
  #5  
Old 12-14-2006, 07:38 AM
mahoni mahoni is offline
Junior Coders
 
Join Date: Dec 2006
Location: Basque Country
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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ía</th>
</tr>
<tr>
<td>

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

</select>
Reply With Quote
  #6  
Old 12-14-2006, 08:08 AM
jscheuer1's Avatar
jscheuer1 jscheuer1 is offline
No Kidding?
 
Join Date: Mar 2005
Location: SE PA USA
Posts: 19,005
Thanks: 19
Thanked 1,135 Times in 1,121 Posts
Blog Entries: 3
Default

Try this out:

Code:
<!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>
__________________
WWWWWWWWWWWW
- John
________________________

Really Show Your Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate
Reply With Quote
  #7  
Old 12-27-2006, 11:57 AM
mahoni mahoni is offline
Junior Coders
 
Join Date: Dec 2006
Location: Basque Country
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks a lot!!!!
It`s all Ok now.

Fuc... differences between explorers!!!

jejeje.
Reply With Quote
Reply

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search

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

Forum Jump


All times are GMT. The time now is 04:44 AM.

Home - Contact Us - Archives - Link to DD - Top 

Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.