Solved

window.location.href to a new page

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

The Eight Noble Truths of Backup and Recovery

How can IT departments tackle the challenges of a Big Data world? This white paper provides a roadmap to success and helps companies ensure that all their data is safe and secure, no matter if it resides on-premise with physical or virtual machines or in the cloud.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Outlook opens HTML email as text 4 24
Select case on click 3 16
Html form and modal / img src -problem 3 12
How to deal with the query string 8 27
This is a PowerShell web interface I use to manage some task as a network administrator. Clicking an action button on the left frame will display a form in the middle frame to input some data in textboxes, process this data in PowerShell and display…
This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
In this tutorial viewers will learn how add a scalable full-width header using CSS3. Create a new HTML document with an internal stylesheet. Set a tiled background.:  Create a new div and name it Header. Position it with position:absolute at the top…
In this tutorial viewers will learn how to code links for mobile sites that, once clicked, send a call or text to a specified number. For a telephone link (once clicked, calls a number), begin with a normal "<a href=" link tag. For the href, specify…

822 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