Proceed to the section with modal

My goal is to create a modal with 4 sections, each loading its content dynamically using the .load() function to the container on the right side.

The challenge I'm facing is that I have a footer menu that triggers the modal to open, and I need it to direct the user to the specific section they clicked on.

For example, if a user clicks on the 'payment methods' option in the footer menu, the modal should open directly in that particular section. Any suggestions on how to achieve this?

This is the script I use to open the modal:

function loadmodal(){
     $('.info_modal').fadeIn();
}

And here's the script for loading the content of the sections within the modal after clicking on the left menu:

function loadcontent(){
     $('.info_modal_content').load('includes/text2.html');
}

Here is the markup structure of the modal:

<div class="info_modal">
    <div class="info_modal_container">
        <h2>Shopping Guide</h2>
        <hr>
        <ul class="info_modal_menu">
            <li>
                 <a href="javascript:void(0)">How to Buy</a>
            </li>
            <li>
                 <a href="javascript:void(0)" onclick="loadcontent()">Payment Methods</a>
            </li>
            <li>
                 <a href="javascript:void(0)">Exchanges and Returns</a>
            </li>
            <li>
                 <a href="javascript:void(0)">Gift Card</a>
            </li>
         </ul>
         <div class="info_modal_content">
             <h2>WHERE TO BUY YOUR GIFT CARD...</h2>
             <p>Your card may be rejected by one of the retailers.</p>
         </div>

         <a href="javascript:void(0)" class="close_contact" onclick="closecontactmodal()"></a>
     </div>
 </div>

Answer №1

Is it possible to pass a URL for the initial load instead?

If your footer has a structure similar to this:

<footer>
  <ul>
    <li><a href="text1.html" class="openModal">Text 1</a></li>
    <li><a href="text2.html" class="openModal">Text 2</a></li>
    <li><a href="text3.html" class="openModal">Text 3</a></li>
    <li><a href="text4.html" class="openModal">Text 4</a></li>
  </ul>
</footer>

You can then add an event handler to .openModal:

$('.openModal').on('click', function(e){
  e.preventDefault();

  var toLoad = $(this).attr('href');

  $('.info_modal_content').load(toLoad);

  $('.info_modal').fadeIn();
});

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Using importNode in the context of Microsoft Edge involves transferring a

I am facing an issue with a dynamic page that has the ability to change its main div content using a bar button. The pages are mostly static except for one which contains JavaScript (RGraph charts). To make it work, I am currently using the following code ...

Create a dynamic select2 field based on the value selected in another dropdown menu

Starting with an initial dropdown where a value needs to be selected: <select id="indexID" name="indexID" class="form-control" onChange="updateSector();" style="width:300px;"> <option value='' selected>Choose an Index</option> ...

What are the steps for implementing CORS?

I recently attempted to set up Ajax calls and stumbled upon the following code snippet: <!DOCTYPE html> <html> <body> <p id="demo">Let AJAX update this text.</p> <button type="button" onclick="loadDoc()">Updat ...

How to Transfer Information Between Two React Components

I recently started learning React and I'm not sure how to approach this task. Basically, I have a list of cars and when the user clicks on each car, it should display detailed information about that specific car in a full-page slide. This is my curr ...

Develop a dynamic thunk and additional reducer to efficiently handle multiple API calls and retrieve data

Using Redux and Redux-Toolkit, I aim to streamline my code by implementing a single asynchronous Thunk and extra reducer for multiple requests. Below is the setup for both the company and client slices: import { createSlice, createAsyncThunk } from &apos ...

Is there a way to integrate PHP functionality into JavaScript?

When it comes to using JavaScript and PHP together, a common challenge is retrieving information from a database and utilizing that data in a JavaScript function. In my case, I need this functionality for implementing password change functionality on a w ...

Looking for a way to assign the object value to ng-model within a select tag from an array of objects? Also, curious about how to easily implement filters on ng-options?

Here is the HTML code for creating a question template: <body ng-controller="myCtrl"> {{loadDataSubject('${subjectList}')}} {{loadDataTopic('${topicList}')}} <h1 class = "bg-success" style="color: red;text-align: ...

Ways to trigger Bootstrap modal through a PHP GET call

I have been searching for a solution to create a modal similar to this one, but I haven't found anything yet. My requirement is that when we pass true in a GET request, the modal should be displayed. Otherwise, if there is no value specified in the $ ...

Tips for extracting and dividing the value of an input field using jQuery

My system includes an input search field where I can enter the make and/or model of a vehicle to conduct a search based on that term. The challenge arises when attempting to distinguish between the make and model, especially for makes with multiple words ...

Exploring the Excitement of PHP Regular Expressions (preg_replace)

Looking for assistance with a regex preg_replace function to clean up HTML content being submitted to my app's controller/model. The goal is to strip away unwanted HTML and convert specific elements into proprietary tags for the app. $postText = $_PO ...

Alignment problem detected in Firefox and Safari, but works perfectly in Chrome

Currently dealing with a CSS problem on my website that is only appearing in Safari and Firefox, while Chrome displays it correctly. The images are not positioning correctly and are stacking instead of being placed in each box as intended. I've expe ...

Navigating through the fetch API request when using express js

I'm looking to use the fetch API to send requests and have those requests handled by Express JS. In my setup, I've put together server.js (Express JS), index.html (home page), and signin.html (sign-in page). index.html <!DOCTYPE html> < ...

Is there a quick way to use AJAX in Rails?

By using the remote:true attribute on a form and responding from the controller with :js, Rails is instructed to run a specific javascript file. For instance, when deleting a user, you would have the User controller with the Destroy action. Then, you woul ...

Enable the click functionality for a disabled MI TextField

I'm utilizing a disabled TextField in my project and updating it using React Hooks useState to modify the value property of the TextField. const [employee , setEmployee] = React.useState('') <TextField fullWidth ...

CSS - How to specify a class within an id using syntax

How can I target a specific tag within an ID using the class name in selector syntax? For example, how can I make the inner "li" turn red in the code snippet below? <html> <head> <style type="text/css"> #navigation li ...

Transform a div's style when hovering over another div using absolute positioning without repetition

I am facing an issue with multiple divs positioned absolutely on top of a primary div with relative positioning. I want one specific div to change its background-color when hovering over another div within the same parent div. Though I know about ad ...

The step-by-step guide on displaying API choices in an Autocomplete feature and keeping them up

Having trouble with updating autocomplete options. An error message pops up in the console log when I try to deselect a tag or select a new one: MUI: The value provided to Autocomplete is invalid. None of the options match with [{"catName":{&qu ...

Discover the secret to loading multiple Google charts simultaneously, despite the limitation that Google charts typically only allow one package to load at a time

I currently have a pie chart displaying smoothly on my webpage, but now I am looking to add a treemap as well. The code snippet for the treemap includes the package {'packages':['treemap']}. It has been stated that only one call should ...

Stepping up Your Next.js Game with the Razorpay Payment Button Integration

When using the Razorpay payment button on a website, it provides a code snippet like this: <form> <script src = "https://cdn.razorpay.com/static/widget/payment-button.js" data-payment_button_id = "pl_FNmjTJSGXBYIfp" data ...

Incorporate an ASP table within an ASP table to enhance data organization and presentation

Is it possible to create a dynamic ASP.NET table structure similar to the one demonstrated below by nesting tables inside table cells? <table> <tr> <td>[Image]</td> <td> <table> <tr> ...