-1

I have to HTML Forms one is visible and one is hidden and submit to the background. I use jquery script to submit the hidden form. I want to redirect my page to http://www.youtube.com/ after submitting the form in the background. Can you add code to my code on how to redirect?

Jquery Script

<script type="text/javascript">
$(function(){
    $("#blast").click(function(){
        if( $("#email").val() == "" ){
        alert("Please enter email value");
        } else {
        // submit the form
            $('#email1,#email2').val($('#email').val());
            $('#form2,#form3').submit();
            alert('Thanks');
            return false;
        }   
    });
    $('#email').keypress(function(e){
        if(e.which == 13){//Enter key pressed
            $('#blast').click();//Trigger search button click event
        }
    });
});

putvande
  • 15,068
  • 3
  • 34
  • 50
  • 2
    [Answer is here](http://stackoverflow.com/questions/503093/how-can-i-make-a-redirect-page-in-jquery-javascript) – u54r Aug 19 '13 at 19:13

2 Answers2

1

If you need to redirect the user after submitting the form, it doesn't make sense to do it with javascript. The whole point of submitting the form with javascript is so that you don't have to reload the page. Just send the user to the page that handles the form data and let that page send the Location: youtube.com/whaaaaarg header.

Sumurai8
  • 20,333
  • 11
  • 66
  • 100
0

You really could have googled how to this in two seconds, but this is how you redirect to another page.

window.location = 'http://www.youtube.com/';

or you can use:

window.location.replace("http://www.youtube.com/");

or

window.location.href = "http://www.youtube.com/";
dezman
  • 18,087
  • 10
  • 53
  • 91