What is the best way to create a fixed contact form on specific pages?

There is a Contact Form 7 on the webpage that I want to make fixed to the right side. Initially, the form is hidden and only the form button (open) is visible. When clicked, the form should open.

Answer №1

Your custom element:

<div onClick="toggleForm()" id="myForm">click here</div>

Custom styling:

<style>
    #myForm{
        background: blue;
        width: 150px;
        height: 150px;
        position: fixed;
        top: 20px;
        right: -100px;
        cursor: hand;
        cursor: pointer;
    }
</style>

Javascript code to open/close the form:

<script>
var isOpen;
function toggleForm(){
    if(isOpen){
        document.getElementById('myForm').style.right='0px';
        document.getElementById('myForm').innerHTML = 'close';
        isOpen=false;
    }
    else{
            document.getElementById('myForm').style.right='-100px';
        document.getElementById('myForm').innerHTML = 'click here';
        isOpen=true;
    }
}
</script>

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

Only if there is an update in the SQL database, I wish to refresh the div

I have created a voting system and I am facing an issue with the data updating. I have implemented a setInterval function in javascript to load the data every 2 seconds, but it's not working as expected. There are no errors shown, but the data is not ...

Utilize a for loop within a query to showcase a modal popup

I have a specific requirement: I want to display a modal popup window based on a for loop using jQuery. I have attempted the following approach, where I want the modal popup to be displayed based on the value of a flag. For example, if the Flag value is 3, ...

Leverage the power of jQuery's .filter() method to pinpoint and target specific text

HTML: <p class="greeting"> hello, my name is kevin. what's yours? </p> jQuery: $("p.greeting").filter(function (){ return $this.text() === "my name is"; }).css("background", "green"); I am attempting to find and highlight the phra ...

Python baseHTTPserver encountering CORS error code 501 (Unsupported method 'OPTIONS') while running in Google Chrome

Hello, I need assistance with base authentication while making an AJAX get/post request to a Python BaseHTTPServer. I managed to modify some lines of code in the Python script to send CORS headers. It works perfectly in modern browsers when I disable HTTP ...

I am currently working on fetching information from a database through ajax and displaying it in a form within a bootstrap modal

If I click on the edit button, I expect to see data populated in a form within a Bootstrap modal using jQuery AJAX method. Here is the image for the edit modal: https://i.stack.imgur.com/LXGo0.png This snippet is for the home page: <?php require_ ...

Preventing the page from auto-refreshing upon button click

Recently, I have encountered an issue with a button on my webpage. Every time the button is clicked, the onclick code executes and then the page refreshes. This was not a problem before, but now it seems to be automatically refreshing the page. The curren ...

When using Math.floor(Math.random() * val.length), the result will be a letter rather than a number

Looking to implement a feature where a different background image is displayed randomly upon page visit or refresh. Currently, specifying the images in an array like the example below works well, but I want to be able to pull from a folder. $(document).r ...

Searching for the perfect jQuery regex to validate date formats

In my application, there is an input box that allows users to enter a string date like "today" or "tomorrow". However, I am facing a new challenge now - dates such as "3 march" or "8 january." The input box includes a dropdown menu feature where users can ...

When the browser size shrinks, turn off the drop-down navigation menu

I'm currently working on a responsive website, and I have encountered an issue with a dropdown menu. When the browser size is reduced to 900px, the menu shifts all the way to the left side. To address this, I added some left padding to keep it off the ...

Using jQuery, disregard elements that are not hidden

Currently, I am working with a jQuery validator and I am attempting to utilize the ignore: ':hidden:not feature for all controls that contain an ID with " selecting" in it. Here is my current code snippet: sb.AppendLine(@" ignore: ':hidden: ...

Is there a way to adjust the size of the canvas element in HTML without compromising quality or resorting to zooming?

I'm currently working on a basic modeling application for the web. The main component of my app is a canvas element that I'm trying to size correctly. However, when I set the height and width using CSS, it scales the entire canvas and compromises ...

Is there a way to insert a colored square into a <button> tag rather than text?

Looking for help with the following HTML: <button name="darkBlue" onclick="setThemeColor(this.name)">Blue</button> <button name="black" onclick="setThemeColor(this.name)">Black</button> I'm interested in replacing the text on ...

Exploring the capabilities of jQuery when it comes to defining ranges of

I am currently working on creating a dynamic range of values for a select box using ajax and jquery. The first dropdown menu has options that will interact with a second dropdown containing a range of numbers. While I know how to set the value of a single ...

Using Handlebars.js to conditionally display data within an object is not functioning as expected

I am attempting to retrieve JSON data value and only display the element if the data is present. However, I am experiencing issues with Handlebar JS. var data = { listBank: [ { "enableSavedCards":"false", "enableAxisAccount":"t ...

The variable req.body.Dates has not been declared

I am currently working on a project that involves dynamically populating two drop down menus using SQL Server. Depending on the selected items, I need to load a specific ejs template using AJAX. My goal is to load data based on the selected criteria. For e ...

Having trouble navigating menus and submenus?

Customizing CSS Styles On my website, I have two different classes: menu and leftside. Both classes include the ul and li elements. However, when I try to use ul and li in the left side as well, they end up matching with the styles of the menu ul and li. ...

Adjust the speed of the remaining divs below to move up when one is deleted using Ajax and jQuery

My div elements are arranged from top to bottom, and when one selected div is removed or faded out, all other divs below it shift up suddenly to fill the gap. While this behavior is functional, I would prefer to slow down the movement of the divs shifting ...

How can we restart jquery if both functions fail to execute within 5 seconds?

I'm in the process of incorporating a timeout or reset into this section of jQuery code. <script type="text/javascript> var $msgNav = $('.nav4'); $msgNav.on('click', handler); function handler() { $('.drop_down_ ...

The input fields within a "form" are not functioning correctly with Jquery

Encountering an issue with my project involving a timetable that allows for dynamically adding rows with Jquery. The following are the codes: <?php session_start(); ?> <html lang="es"> <head> <meta charset="iso-8859-1"> ...

Automatically redirect users on page refresh using jQuery

I am attempting to use jQuery to detect when the user refreshes the page in order to redirect, but I can't seem to get it working. Can someone help me figure out what is wrong with this code? <?php include 'instagram.php'; ?> <! ...