Results 1 to 7 of 7

Thread: document.form.options.value in mozilla

  1. #1
    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.

  2. #2
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    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!

  3. #3
    Join Date
    Dec 2004
    Location
    UK
    Posts
    2,358
    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.

    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

  4. #4
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    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?
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  5. #5
    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&#237;a</th>
    </tr>
    <tr>
    <td>

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

    </select>

  6. #6
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    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>
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

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

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •