title: javascript Redirect submitted form after clicking ok in the alert box
body: <p>I have a form</p>
  
  <p>onclick confirm , i need to direct it to a particular url</p>
  
  <p></p>
  
  <pre><code>function submitdata() { 
       if(confirm("Are You Sure You Want To Proceed?")) {
          location.replace("http://www.w3schools.com");
      } else { 
          alert("Cancelling"); 
      }
  
  }
  &lt;/script&gt;
  </code></pre>
  
  <p>After submitting this form submitdata() is called.</p>
  
  <p>then i am getting an alert.</p>
  
  <p>BUT MY FORM is not getting redirected</p>
  
  <pre><code>&lt;form id="registration_form" action="" method="post" onsubmit="return submitdata();"&gt;
  
          &lt;div id="state"&gt;&lt;/div&gt;
  
  
           &lt;div class="reg-id"&gt;
              &lt;label&gt;
                  &lt;input placeholder="State:" type="text" tabindex="3" name="user_state" id="reg_state" value=""&gt;
              &lt;/label&gt;
  
          &lt;/div&gt;
  
          &lt;div class="reg-id"&gt;
              &lt;label&gt;
                  &lt;input placeholder="City:" type="text" tabindex="3" name="user_city" id="reg_city" value=""&gt;
              &lt;/label&gt;
          &lt;/div&gt;
  
           &lt;div class="reg-id-last"&gt;
              &lt;label&gt;
                  &lt;input placeholder="Zip/Postal:" type="text" tabindex="3" name="user_zip" id="reg_zip" value=""&gt;
              &lt;/label&gt;
          &lt;/div&gt;
              &lt;input type="submit" value="Response" tabindex="3" name="reg_btn" id="id-submit"&gt;
          &lt;/div&gt;
  
      &lt;/form&gt;
  </code></pre>