Search code examples
javascriptnew-window

how to open a new window for a specified java code


I have the code below on a page. It works. I just can not find out how to make it to open in a new window. window.open doesn't work on it. Help is needed.

<form method="post">
<input type="RADIO" name="button" value="index1.html" checked>this button goes to index1.html (Default)<BR>
<input type="RADIO" name="button" value="index2.html">this button goes to index2.html<BR>         
<input type="RADIO" name="button" value="index3.html">this button goes to index3.html<BR>
<input type="submit" value="Continue">


<script>
$(function(){
$("form").submit(function(e) {
    e.preventDefault();
    window.location = $(this).find('input[type="radio"]:checked').val();
});
});
</script>

</form>

Solution

  • Here is an update that should work for you using window.open:

    http://jsfiddle.net/yQLmL/

    <form method="post">
        <input type="RADIO" name="button" value="http://www.google.com" checked>this button goes to index1.html (Default)
        <BR>
        <input type="RADIO" name="button" value="http://www.yahoo.com">this button goes to index2.html
        <BR>
        <input type="RADIO" name="button" value="http://www.stackoverflow.com">this button goes to index3.html
        <BR>
        <input type="submit" value="Continue">
    </form>
    
    <script>
        $(function () {
            $("form").submit(function (e) {
                e.preventDefault();
                var url = $(this).find('input[type="radio"]:checked').val();
                window.open(url);
    
            });
        });
    </script>