Solved

window.location.href to a new page

Posted on 2007-11-20
5
3,448 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
Thanks a lot!
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this.Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it is …
JavaScript can be used in a browser to change parts of a webpage dynamically. It begins with the following pattern: If condition W is true, do thing X to target Y after event Z. Below are some tips and tricks to help you get started with JavaScript …
In this tutorial viewers will learn how to position items using CSS's three positioning types Create a new HTML document with an internal stylesheet.: Create another div in CSS and name it Absolute : Type "position:absolute;" and "top:10px; left:50p…
In this tutorial viewers will learn how to style a corner ribbon overlay for an image using CSS Create a new class by typing ".Ribbon":  Define the class' "display:" as "inline-block": Define its "position:" as "relative": Define its "overflow:" as …

772 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

12 Experts available now in Live!

Get 1:1 Help Now