Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6

Thread: Element Control

  1. #1
    Regular Coder
    Join Date
    Jun 2002
    Location
    Brisbane, Australia
    Posts
    181
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Element Control

    When manipulating a form element, i use:

    document.formname.elements["item_name"]. ... etc.

    but that only works in Mozilla and NS.
    This is because these browsers dont like _'s and require the form element to be represented in a readable string.



    For Internet Explorer do i just do:

    document.formname.item_name. ... ?



    or is there a better way?
    -mR_eGo
    _______________________
    Programming since
    3 years old.

  • #2
    Senior Coder
    Join Date
    Jun 2002
    Location
    Zwolle, The Netherlands
    Posts
    1,120
    Thanks
    2
    Thanked 31 Times in 31 Posts
    most of the time i use:
    document.forms["formname"].elements["elementname"]
    works in ie and moz afaik
    I am the luckiest man in the world

  • #3
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    11,068
    Thanks
    0
    Thanked 256 Times in 252 Posts
    document.formname.elements["item_name"] works in all browsers. I have had no problem with IE using that method.
    Glenn
    ____________________________________

    My Blog
    Tower of Hanoi Android app (FREE!)
    Tower of Hanoi Leaderboard
    Samegame Facebook App
    vBulletin Plugins
    ____________________________________

  • #4
    Regular Coder
    Join Date
    Jun 2002
    Location
    Brisbane, Australia
    Posts
    181
    Thanks
    1
    Thanked 0 Times in 0 Posts
    document.forms["userdefform"].elements["fieldname"].options[0] = new Option("text", "value");
    IE: FAILED
    NS: SUCCESS

    document.userdefform.elements["fieldname"].options[0] = new Option("text", "value");
    IE: FAILED
    NS: SUCCESS

    anything else?
    -mR_eGo
    _______________________
    Programming since
    3 years old.

  • #5
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    11,068
    Thanks
    0
    Thanked 256 Times in 252 Posts
    I've created a simple page with your code in it and it works for me. Im using IE5.5. Can I see your whole code?
    Glenn
    ____________________________________

    My Blog
    Tower of Hanoi Android app (FREE!)
    Tower of Hanoi Leaderboard
    Samegame Facebook App
    vBulletin Plugins
    ____________________________________

  • #6
    Senior Coder
    Join Date
    Jun 2002
    Location
    Zwolle, The Netherlands
    Posts
    1,120
    Thanks
    2
    Thanked 31 Times in 31 Posts
    Code:
    <html>
    <head>
    <title></title>
    <script language="javascript">
    function addelement () {
      document.forms["formname"].elements["elementname"].options[0] = new Option("", "");
      document.forms["formname"].elements["elementname"].options[1] = new Option("text", "value");
    }
    
    function showvalue (objSelect) {
      alert (objSelect.options[objSelect.options.selectedIndex].value);
    }
    </script>
    </head>
    
    <body>
    
    <form name="formname">
    <select name="elementname" onchange="showvalue(this)">
    </select>
    <input type="button" onClick="addelement();" value="add">
    </form>
    </body>
    </html>
    works in ie
    I am the luckiest man in the world


  •  

    Posting Permissions

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