?
Solved

window.location.href to a new page

Posted on 2007-11-20
5
Medium Priority
?
3,483 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 2000 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

WordPress Tutorial 3: Plugins, Themes, and Widgets

The three most common changes you will make to your website involve the look (themes), the functionality (plugins), and modular elements (widgets).

In this article we will briefly define each again, and give you directions on how to install them.

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…
This article explains how to prepare an HTML email signature template file containing dynamic placeholders for users' Azure AD data. Furthermore, it explains how to use this file to remotely set up a department-wide email signature policy in Office …
In this tutorial viewers will learn how to style elements, such a divs, with a "drop shadow" effect using the CSS box-shadow property Start with a normal styled element, such as a div.: In the element's style, type the box shadow property: "box-shad…
The viewer will learn the benefit of using external CSS files and the relationship between class and ID selectors. Create your external css file by saving it as style.css then set up your style tags: (CODE) Reference the nav tag and set your prop…
Suggested Courses

777 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