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
Solved

window.location.href to a new page

Posted on 2007-11-20
5
3,464 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

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
html input 8 42
forgetful about js objects 8 46
ASP Classic - JavaScript - Get value from form in iFrame and pass to main page. 2 21
Insert Button on a table 16 37
This article describes how to create custom column layout styles for Bootstrap. The article uses 5 columns to illustrate the concept, but the principle can be extended to any number of columns.
Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
In this tutorial viewers will learn how to embed an audio file in a webpage using HTML5. Ensure your DOCTYPE declaration is set to HTML5: : The declaration should display (CODE) HTML5 is supported by the most recent versions of all major browsers…
HTML5 has deprecated a few of the older ways of showing media as well as offering up a new way to create games and animations. Audio, video, and canvas are just a few of the adjustments made between XHTML and HTML5. As we learned in our last micr…

840 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