Learn free online HTML5, javascript, and jquery Tutorials by Examples

Saturday 17 May 2014

Using Hyperlink from Select Option in javascript

-------------------------------------------------- 
<form id="chk">
        <select><!--onchange="open_this()"ADD this event to open link in new tab without using Go button-->
            <option>select</option>
            <option id="chk1">www.google.com</option>
            <option id="chk2">www.fb.com</option>
        </select>
        <input type="button" value="Go" onclick="open_this()" />
    </form>


<script>
    function open_this(){
        if(document.getElementById("chk1").selected==true){
            window.open('http://www.google.com/','_blank');
            }
            if(document.getElementById("chk2").selected==true){
                window.open('https://www.fb.com/','_blank');
            }
    }
</script>
-------------------------------------------------- 

No comments:

Post a Comment