Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • How to get the Select Dropdown Option Value after Click on Button

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 119
    Comment on it

    Hello Readers,

    If I want to Select Drop down Option Value after Click on Button (not submit) then we use the below code:

    <select name="option">
    <option value="http://findnerd.com">Findnerd</option>
    <option value="http://facebook.com">Facebook</option>
    <option value="http://twitter.com">Twitter</option>
    </select>    
    <button type="button" onclick="openLink(document.forms['myForm1'])">Click</button>
    
    
    <form name="myForm2" method="post">                
    <select name="option">
    <option value="http://linkedin.com">Linkedin</option>
    <option value="http://google.com">Google</option>        
    </select>    
    <button type="button" onclick="openLink(document.forms['myForm2'])">Click</button>
    </form>
    
    <script type="text/javascript">
        function openLink(myForm)
        {                    
        var selectedIndex = myForm.elements["urls"].selectedIndex;
        var url = myForm.elements["urls"].options[selectedIndex].value;
        window.open(url);
        }            
        </script>
    

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: