javascript - Button Redirect Using JQuery
In my PHP site, I am trying to get a button to redirect to a PayPal page for payment if a user has chosen PayPal from the dropdown. Normally, the button would go to the next page to authorize the credit card payment, but since the addition of PayPal, I need that button to redirect only if PayPal is chosen, otherwise it should still go to the next page in the payment process.
Can someone help me make my code work? I'm not very experienced, so I appreciate any help.
<tr>
<td colspan="2">
<label>Card Type <span>*</span>
<select name="CardType" id="CardType">
<option value="" selected Select--</option>
<option value="Amex">American Express</option>
<!--<option value="Discover">Discover</option>-->
<option value="MasterCard">MasterCard</option>
<option value="PayPal">PayPal</option>
<option value="Visa">Visa</option>
</select>
</label>
</td>
</tr>
<tr>
<td colspan="2" align="right"><br />
<button type="button" >« Back</button>
<button type="button" >Proceed »</button>
</td>
</tr>
What I want is something like this:
<script type="text/javascript">
if ($('#CardType').val() == 'PayPal'){
$('next').click(window.location.href = "https://www.paypal.com/cgi-bin/webscr?cmd=_xclick&business=BUSINESSNAME");
}
</script>
Answer
Solution:
check out this jsfiddle
(the link won't actually go anywhere in jsfiddle because the site doesn't allow cross-origin framing; however, if you open up your console, you'll see that the code does in fact work.)
Answer
Solution:
Try this. When the page is ready it will bind
click
event. After that whenever you click button it will check theCardType
and set the location.Here is the fiddle: http://jsfiddle.net/3DA5m/