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 3 of 3
  1. #1
    New Coder
    Join Date
    Nov 2008
    Location
    Surprise, AZ
    Posts
    21
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Thumbs up Setting SELECTED in Select/List

    Hello,

    I'm trying to change the selected index of a List/Menu based on the value of a Text field, I can pull data and alerts, but setting the selection is not working. Any ideas?

    Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>Untitled Document</title>
    </head>
    <script language="javascript">
    function getExtension(){
     var myType = document.form1.theExtension;
     var daStr = document.form1.theList;
     alert(myType.value);
     for(var i = 0; i < document.form1.theList.length; i++){
      alert(daStr.options[i].text);
      if(daStr.options[i].text == myType.value){
       daStr.options[i].selected == true;
       alert("Yes");
       alert(daStr.options[i].text.indexOf(myType.value));
      }
      else{
       alert("No");
       alert(daStr.options[i].text.indexOf(myType.value));
      }
     }
    }
    </script>
    <body>
    <form id="form1" name="form1" method="post" action="">
      <label for="theList"></label>
      <p>
        <select name="theList" id="theList">
          <option>Make a Selection</option>
          <option value="2">My DOC</option>
          <option value="1">My PDF</option>
          <option value="3">My XLS</option>
        </select>
      </p>
      <p>
        <label for="theExtension"></label>
        <input name="theExtension" type="text" id="theExtension" value="My PDF" />
      </p>
      <p>
        <label for="Button">Call It</label>
        <input name="Button" type="button" id="Button" onclick="getExtension();" value="Call It" />
    </p>
    </form>
    </body>
    </html>
    Thanks to anyone that can help or point me in the right direction.
    Regards,
    Yarrokon

  • #2
    Senior Coder tomws's Avatar
    Join Date
    Nov 2007
    Location
    Arkansas
    Posts
    2,644
    Thanks
    29
    Thanked 330 Times in 326 Posts
    Code:
       daStr.options[i].selected == true;
    The double equal is a test for equality. Single is the assignment operator.
    Are you a Help Vampire?

  • #3
    New Coder
    Join Date
    Nov 2008
    Location
    Surprise, AZ
    Posts
    21
    Thanks
    4
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by tomws View Post
    Code:
       daStr.options[i].selected == true;
    The double equal is a test for equality. Single is the assignment operator.
    OMG, how did I miss that. This is what I get for working late, egg on my face.

    Thank you for seeing this.
    Regards,
    Yarrokon


  •  

    Posting Permissions

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