Skip to content

Commit

Permalink
- First commit of actual codebase
Browse files Browse the repository at this point in the history
  • Loading branch information
Adam committed Sep 30, 2008
1 parent 266181f commit 4cabc3a
Show file tree
Hide file tree
Showing 6 changed files with 207 additions and 0 deletions.
19 changes: 19 additions & 0 deletions MIT-LICENSE.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
Copyright (c) 2008 Adam Daniels

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
41 changes: 41 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# Simple State/Province Select plugin for jQuery

This plugin links a country select tag to a state/province select tag.

The states populate from an array, so no extra requests to the server are required.

Currently supporting these countries: Canada, United States

## Example
$(document).ready(function() {
$('#country').linkToStates('#state');
});

Also see the included example.html


## Dependencies

* jQuery (www.jquery.com)
* jQuery Select Boxes Plugin (www.texotela.co.uk/code/jquery/select)

## License
Copyright (c) 2008 Adam Daniels

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
31 changes: 31 additions & 0 deletions example.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<html>
<head>
<title>jQuery State Select Plugin Test</title>
<script type="text/javascript" src="jquery-latest.pack.js"></script>
<script type="text/javascript" src="jquery.selectboxes.pack.js"></script>
<script type="text/javascript" src="jquery.stateselect.js"></script>
<script type="text/javascript">
$(document).ready(function() {
$('#country').linkToStates('#province');
});
</script>
</head>
<body>
<form>
<p>
<label>Province/State</label><br />
<select name="province" id="province">
<option value="">Please select a country</option>
</select>
</p>
<p>
<label>Country</label><br />
<select name="country" id="country">
<option>Please select</option>
<option value="Canada">Canada</option>
<option value="United States">United States</option>
</select>
</p>
</form>
</body>
</html>
1 change: 1 addition & 0 deletions jquery-latest.pack.js

Large diffs are not rendered by default.

14 changes: 14 additions & 0 deletions jquery.selectboxes.pack.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

101 changes: 101 additions & 0 deletions jquery.stateselect.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
/*
* Simple State/Province Select plugin for jQuery
*
* Example:
* $(document).ready(function() {
* $('#country').linkToStates('#state');
* });
*
* Copyright (c) 2008 Adam Daniels
* Licensed under the MIT License *
*/
;(function($) {
var canadian_provinces = {
'Ontario' : 'Ontario',
'Quebec' : 'Quebec',
'Manitoba' : 'Manitoba',
'Alberta' : 'Alberta',
'New Foundland and Labrador' : 'New Foundland and Labrador',
'Nova Scotia' : 'Nova Scotia',
'Prince Edward Island' : 'Prince Edward Island',
'Saskatchewan' : 'Saskatchewan',
'Nunavut' : 'Nunavut',
'British Columbia' : 'British Columbia',
'New Brunswick' : 'New Brunswick',
'Yukon' : 'Yukon',
'Northwest Territories' : 'Northwest Territories'
}

var us_states = {
'Alabama' : 'Alabama',
'Alaska' : 'Alaska',
'Arizona' : 'Arizona',
'Arkansas' : 'Arkansas',
'California' : 'California',
'Colorado' : 'Colorado',
'Connecticut' : 'Connecticut',
'Delaware' : 'Delaware',
'Florida' : 'Florida',
'Georgia' : 'Georgia',
'Hawaii' : 'Hawaii',
'Idaho' : 'Idaho',
'Illinois' : 'Illinois',
'Indiana' : 'Indiana',
'Iowa' : 'Iowa',
'Kansas' : 'Kansas',
'Kentucky' : 'Kentucky',
'Louisiana' : 'Louisiana',
'Maine' : 'Maine',
'Maryland' : 'Maryland',
'Massachusetts' : 'Massachusetts',
'Michigan' : 'Michigan',
'Minnesota' : 'Minnesota',
'Mississippi' : 'Mississippi',
'Missouri' : 'Missouri',
'Montana' : 'Montana',
'Nebraska' : 'Nebraska',
'Nevada' : 'Nevada',
'New Hampshire' : 'New Hampshire',
'New Jersey' : 'New Jersey',
'New Mexico' : 'New Mexico',
'New York' : 'New York',
'North Carolina' : 'North Carolina',
'North Dakota' : 'North Dakota',
'Ohio' : 'Ohio',
'Oklahoma' : 'Oklahoma',
'Oregon' : 'Oregon',
'Pennsylvania' : 'Pennsylvania',
'Rhode Island' : 'Rhode Island',
'South Carolina' : 'South Carolina',
'South Dakota' : 'South Dakota',
'Tennessee' : 'Tennessee',
'Texas' : 'Texas',
'Utah' : 'Utah',
'Vermont' : 'Vermont',
'Virginia' : 'Virginia',
'Washington' : 'Washington',
'West Virginia' : 'West Virginia',
'Wisconsin' : 'Wisconsin',
'Wyoming' : 'Wyoming'
}

$.fn.extend({
linkToStates: function(state_select_id) {
$(this).change(function() {
var country = $(this).attr('value');
$(state_select_id).removeOption(/.*/);
switch (country) {
case 'Canada':
$(state_select_id).addOption(canadian_provinces, false);
break;
case 'United States':
$(state_select_id).addOption(us_states, false);
break;
default:
$(state_select_id).addOption({ '' : 'Please select a Country'}, false);
break;
}
});
}
});
})(jQuery);
Expand Down

0 comments on commit 4cabc3a

Please sign in to comment.