Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URLs added here will be added as <link>s in order, and before the CSS in the editor. You can use the CSS from another Pen by using its URL and the proper URL extension.

+ add another resource

JavaScript

Babel includes JSX processing.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Behavior

Auto Save

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                <div class="font-sans antialiased w-screen">
  <div class="w-screen flex flex-col space-x-0 h-screen">
    <div class="flex-1 min-w-full p-4">
      <h3 class="text-xl font-semibold">Update an iframe src to load specific map features in Mango</h3>
      <ol class="text-base p-4">
        <li>Select a state from the dropdown list to update the permalink used as the iframe src.
        </li>
      </ol>
      <hr>
      <form>
        <label class="text-base font-semibold" for="id">Choose a state:</label>
        <select name="features" id="id" class="border px-1 py-1 rounded-lg">
          <option value="" selected disabled>Please select...</option>
          <option value="Florida">Florida</option>
          <option value="Kentucky">Kentucky</option>
          <option value="Montana">Montana</option>
          <option value="Washington">Washington</option>
        </select>
      </form>
    </div>
    <div class="mx-none flex-1 flex-grow">
      <iframe id="iframe" class="h-screen lg:w-screen md:w-screen sm:min-w-full" src="https://mangomap.com/examples/maps/51841/category-map"></iframe>
    </div>
  </div>
</div>

              
            
!

CSS

              
                
              
            
!

JS

              
                // Ensure that the jQuery code runs only after the entire HTML document has loaded.
$(document).ready(function() {
  // Attach a 'change' event listener to the dropdown menu with the id 'id'.
  // This event triggers whenever the user selects a different option in the dropdown.
  $("#id").change(function() {
    // Retrieve the value of the selected option in the dropdown.
    var fid = $(this).val();

    // Check if the value is empty (i.e., no state is selected). If so, alert the user and exit the function.
    if (!fid) {
      alert('Please select a state.');
      return;
    }

    // Construct the new URL for the iframe by appending the selected state ID (fid) to the base URL.
    // Use encodeURIComponent to safely encode the state ID to handle special characters correctly and prevent XSS attacks.
    var newURL = `https://mangomap.com/examples/maps/51841/category-map?layer=c02f3720-15d4-11e6-86d6-06c182e4d011&field=gid&value=${encodeURIComponent(fid)}`;

    // Update the 'src' attribute of the iframe with the new URL, causing the iframe to load the new map corresponding to the selected state.
    $("#iframe").attr('src', newURL);
  });
});

              
            
!
999px

Console