www.webdeveloper.com
Results 1 to 8 of 8

Thread: Refresh dropdown ( Select ) menu with javascript

  1. #1
    Join Date
    Dec 2013
    Posts
    4

    Refresh dropdown ( Select ) menu with javascript

    I have a drop down menu. In the SELECT , I have one item selected( "AAA"). I need the user to push a button on the web page to update the SELECT ( which should show CCC as being selected) in the drop down list. The value "3" is getting there,
    however the problem is the SELECT is not getting refreshed to show the user "CCC" is currently selected.
    I do NOT want the page to refresh.

    --------------------------
    Code:
    function cDitto() {
    strSelectedIndex="2";
    strValue="3";
    intMaxLength=document.form1.length;
    for(intkk=elemnum;intkk<intMaxLength;intkk++){
       mySelect=document.form1[intkk];
    
      mySelect.options[strSelectedIndex].value=strValue;
      mySelect.selectedIndex=strSelectedIndex;
    }
    }
    ...
    snippet
    ...
    HTML Code:
    <select Name="cropnum01" width="13" class="dropdown">
       <option Value="1"  SELECTED>AAA</option>
       <option Value="2" >BBB</option>
       <option Value="3" >CCC</option>
       <option Value="4" >DDD</option>
    </select>
    -----------

    Suggestions?

    TIA
    shall42

  2. #2
    Join Date
    Dec 2005
    Location
    FL
    Posts
    7,259
    Try this...
    Code:
    <!DOCTYPE html>
    <html lang="en">
    <head>
    <meta charset="UTF-8" />
    
    <title> Untitled </title>
    
    </head>
    <body>
    <select id="SBox0" name="cropnum01" width="13" class="dropdown">
       <option value="1" SELECTED>AAA</option>
       <option value="2" >BBB</option>
       <option value="3" >CCC</option>
       <option value="4" >DDD</option>
    </select>
    <button onclick="document.getElementById('SBox0').selectedIndex=2">Force CCC</button>
    </body>
    </html>
    Last edited by JMRKER; 12-12-2013 at 04:52 PM.

  3. #3
    Join Date
    Dec 2013
    Posts
    4
    That did not work for me. I will continue to work on it. Thanks,

  4. #4
    Join Date
    Dec 2005
    Location
    FL
    Posts
    7,259
    Quote Originally Posted by shall42 View Post
    That did not work for me. I will continue to work on it. Thanks,
    That response is not very helpful.
    Why did it not work for you?
    It works fine for me.

    What errors are you getting?

  5. #5
    Join Date
    Dec 2013
    Posts
    4
    You are right. Your way does WORK.
    I had mine in a FORM. After pressing the button,
    the "AAA" changes to "CCC" for a second. Then it goes back
    to "AAA".

  6. #6
    Join Date
    Dec 2005
    Location
    FL
    Posts
    7,259
    Change the submit section of your form tag.
    For example <form id="xxx" action="yyy" onsubmit="return validateInformation()">

    Then in the function "validateInformation()" return false until the information is what you expect, in which case return true.

    If there is no information to validate from the form tag, then just use:
    <form id="xxx" action="" onsubmit="return false">

  7. #7
    Join Date
    Dec 2013
    Posts
    4
    BRILLIANT!!!!
    Thanks.

  8. #8
    Join Date
    Dec 2005
    Location
    FL
    Posts
    7,259
    You're most welcome.
    Happy to help.
    Good Luck!

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Posting Permissions

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



Recent Articles