jpking72
asked on
window.location.href to a new page
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)
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
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
It is a button. actually I'm calling it from a perl script as shown below:
print "<html><head><title>Morgan as 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:cance lOrder();\ " />
</label></p><p> </p>< /body></ht ml> ";
========================== ========== ====
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";
}
=================
print "<html><head><title>Morgan
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:cance
</label></p><p> </p><
==========================
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";
}
=================
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>
ASKER
Thanks a lot!