Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Dynamic category dropdown and map generation for survey form
- add_filter("gform_pre_render_6", "monitor_single_dropdown");
- function monitor_single_dropdown($form){
- ?>
- <script type="text/javascript">
- jQuery(document).ready(function(){
- //** Dynamic dropdown code **
- //clone the category dropdown
- var clone_select = jQuery('#input_13').clone();
- //bind change function to state dropdown
- jQuery('#input_6_34').bind('change', function() {
- //get selected state
- var selectedValue = jQuery("#input_6_34").val();
- //filter out everything but bases in that state
- var clone_subset = clone_select.find('option')
- .filter('[value="' + selectedValue + '"]')
- .nextUntil('.level-0')
- .clone();
- jQuery('#input_13').empty().append( clone_subset );
- jQuery("#input_13").find("option").each(function (index, option) {
- jQuery(option).html(jQuery(option).html().replace(' ',''));
- });
- });
- //** Geocode city and state to a lat/long and refresh the map
- function ChangeMap() {
- var geocoder = new GClientGeocoder();
- var address;
- if ( !jQuery("#map_search").val() ) {
- address = jQuery("#input_13 option:selected").text() + ", " + jQuery("#input_6_34 option:selected").text();
- }
- else {
- address = jQuery("#map_search").val();
- }
- if ( geocoder ) {
- geocoder.getLatLng(
- address,
- function(point) {
- if ( !point ) {
- alert(address + " not found");
- } else {
- map.setCenter(point);
- marker.setPoint(point);
- marker.show();
- map.setZoom(13);
- //set hidden form fields to lat/long
- jQuery("#input_6_32").val(point.lat());
- jQuery("#input_6_33").val(point.lng());
- }
- }
- );
- }
- return false;
- }
- //bind dropdowns to ChangeMap function
- jQuery('#input_13, #input_6_34').bind('change', function() {
- ChangeMap();
- });
- //bind search button to ChangeMap function
- jQuery('#map_search_button').click(function() {
- ChangeMap();
- jQuery("#map_search").val("");
- });
- });
- </script>
- <?php
- return $form;
- }
Advertisement
Add Comment
Please, Sign In to add comment