Solved

window.location.href to a new page

Posted on 2007-11-20
5
3,455 Views
Last Modified: 2010-04-21
I have a "checkout" form for an online bookstore...the on the place order page the customer can either enter his credit card number and press submit, or he can cancel the order with a "cancel order" button.  When I try to cancel the order, I use "onclick="window.location.href=http://localhost:8080/morgana.html".  I've also tried moving the javascript to the script header at the top, or even in a separate javascript file.  It basically acts like it submits the form and proceeds with the order, which is not what I want it to do...I just want it to cancel everything and move back to the home page (morgana)
0
Comment
Question by:jpking72
  • 2
  • 2
5 Comments
 
LVL 19

Expert Comment

by:darron_chapman
ID: 20325088
My guess is that you've set up the Cancel button as type="submit" when it just need to be type="button" ... if this isn't the case, then please post your code
0
 
LVL 9

Accepted Solution

by:
blue_hunter earned 500 total points
ID: 20325103
you might as well try the code below

<script language="javascript">
function jsRedirect(){
window.location.href="http://localhost:8080/morgana.html";
return false;
}
</script>

<input type="button" value="cancel order" onclick="return jsRedirect();" />
0
 

Author Comment

by:jpking72
ID: 20325145
It is a button.  actually I'm calling it from a perl script as shown below:

print "<html><head><title>Morganas Checkout</title>";
      print "<script type=\"text/javascript\" src=\"/admin.js\"></script>";
      
=======================================

print "<p><span class=\"style6\">Payment Info </span><label></label>
</p><form id=\"confirm\" name=\"confirm\" method=\"post\" action=\"confirm.pl\" >
  <label><select name=\"payid\" size=\"6\" id=\"payment\">
  <option>Cash</option>
  <option>MasterCard</option>
  <option>Visa</option>
  <option>American Express</option>
  <option>Discover</option>
  <option>Debit</option>";
 
 print "</select></label><p>Card No.<label>
  <input type=\"text\" name=\"cardno\" id=\"cardno\" /></label><input type=\"hidden\" name=\"cid\" value=$custID />
</p><p><label><input name=\"submit\" type=\"submit\" id=\"Place Order\" value=\"Place Order\" /></form>";
 print "<input name=\"cancelorder\" type=\"button\" id=\"cancelorder\" value=\"Cancel Order\" onclick=\"javascript:cancelOrder();\"  />
  </label></p><p>&nbsp;</p></body></html> ";

========================================
from admin.js: the hello alert works.  I've tried moving the </form> tag

function cancelOrder() {
      
      alert('hello');
      window.location.href="http://localhost:8080/morganas3.html";
      
      }

=================
0
 
LVL 9

Expert Comment

by:blue_hunter
ID: 20325206
modify as below
print "<input name=\"cancelorder\" type=\"button\" id=\"cancelorder\" value=\"Cancel Order\" onclick=\"return cancelOrder();\"  />
 
 

<script language="javascript">

function cancelOrder() {

      

      alert('hello');

      window.location.href="http://localhost:8080/morganas3.html";

      return false;

}

</script>

Open in new window

0
 

Author Closing Comment

by:jpking72
ID: 31410282
Thanks a lot!
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
The viewer will the learn the benefit of plain text editors and code an HTML5 based template for use in further tutorials.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)

863 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

24 Experts available now in Live!

Get 1:1 Help Now