Creating a nice payment selector button for your website using HTML, CSS and jQuery.
13 October 2011
Leave Comment
We'll be making this (demo):

The HTML.
Let's start by writing up the HTML necessary for us to make this nice looking button.
Notice how we're wiring up two different CSS classes. This is in case you want to offer different payment types and you want to set a same default button style, but also change the background image (credit card, moneygram, deposit, etc.).
The CSS.
Great, now we need two styles for each event in case the mouse is on the button, and when the mouse is off the button.
The Javascript
First, remember to wrap everything in the document ready event.
Next, let's wire up the events for when the mouse enter or leaves the button:
Next let's hook up the event so that when a user clicks anywhere inside the container box, the radiobutton is selected.
And finally the events when the mouse enter and leaves. We're going to switch out CSS class during each of these events. Giving the buttons a nice shine on mouse over.
And we're done!
Now we have a nice button that responds well to mouse events and is good from a UX view.
You can see the entire example here:
http://jsfiddle.net/...errez/ZbFWu/71/

The HTML.
Let's start by writing up the HTML necessary for us to make this nice looking button.
<div class="paymentoption creditcard">
<input class="optionradio" name="paymenttype" value="deposit" type="radio" />
<span class="optionlabel">Credit Card</span>
</div>
Notice how we're wiring up two different CSS classes. This is in case you want to offer different payment types and you want to set a same default button style, but also change the background image (credit card, moneygram, deposit, etc.).
The CSS.
/* The entire button's container box.*/
.paymentoption {
width:233px;
height:125px;
float:left;
padding-left:5px;
padding-top:3px;
}
/* The radio button input */
.optionradio {
margin-left:4px;
margin-top:4px;
}
/* The text beside the radio button input */
.optionlabel {
color:#00246C;
font-family:Tahoma;
font-size:14px;
font-weight:bold;
}
Great, now we need two styles for each event in case the mouse is on the button, and when the mouse is off the button.
.creditcard{
background-image: url('http://i.imgur.com/qoIwQ.png');
}
.creditcardhover {
background-image: url('http://i.imgur.com/KEIff.png');
}
The Javascript
First, remember to wrap everything in the document ready event.
$(document).ready(function() {
//Your code here.
}
Next, let's wire up the events for when the mouse enter or leaves the button:
$(document).ready(function() {
$('.paymentoption').mouseenter(function() {
$(this).css('cursor', 'hand');
});
$('.paymentoption').mouseleave(function() {
$(this).css('cursor', 'pointer');
});
}
Next let's hook up the event so that when a user clicks anywhere inside the container box, the radiobutton is selected.
$('.paymentoption').click(function() {
$(this).find('input[name="paymenttype"]').prop('checked', true);
});
And finally the events when the mouse enter and leaves. We're going to switch out CSS class during each of these events. Giving the buttons a nice shine on mouse over.
$('.creditcard').mouseenter(function() {
$(this).removeClass("creditcard").addClass("creditcardhover");
});
$('.creditcard').mouseleave(function() {
$(this).removeClass("creditcardhover").addClass("creditcard");
});
And we're done!
Now we have a nice button that responds well to mouse events and is good from a UX view.
You can see the entire example here:
http://jsfiddle.net/...errez/ZbFWu/71/
0 Comments On This Entry
Trackbacks for this entry [ Trackback URL ]
28 user(s) viewing
About Me

Bienvenidos! I'm a USA ex-pat living in Bolivia for the past 10 years. Web development is my forte with a heavy lean for usability and optimization. I'm fluent in both English and Spanish. I guest write for the popular Python website Python Central. Visit my website.
My Blog Links
Recent Entries
-
-
-
-
-
How to create a signature form for iPad and mobile devices using HTML5 and Canvas.
on Nov 27 2012 08:15 AM
Recent Comments
-
laytonsdad
on Apr 30 2013 11:30 AM
Dream.In.Code Badge Generator! Share your flair on your site or blog.
-
-
Jstall
on Nov 04 2012 09:18 AM
The Pragmatic Bookshelf mega blowout sale - 40% off select Ruby on Rails books.
-
-
tylrwb
on Jun 26 2012 07:34 PM
C# and MVC3 - Uploading and parsing an Excel document is easier than it seems.
Categories
|
|











|