Invoking an HTML popup within a JavaScript function

Here is a question. In my project, I have the following JavaScript function:

<script type="text/javascript" language="javascript">   
$(document).ready(function(){
    PopUpHide();
});
function PopUpShow(popup_title, pk_post_add){
    document.getElementById("id_popup_title").innerHTML = popup_title;
    document.getElementById('id_pk_post_add').value=pk_post_add;
    $("#popup1").show();
    $(document).keyup(function(ev){
    if(ev.keyCode == 27)
        $("#popup1").hide();
    });
}
function PopUpHide(){
    $("#popup1").hide();
}
</script>

The popup that calls the function looks like this:

<div class="b-popup" id="popup1" >
    <div class="b-popup-content">
        <div style="width:100%; height:10%;">
        <center><b><font color=#000000 size="5" "Lucida Sans Unicode", "Lucida Grande", sans-serif><p id="id_popup_title"></p></font></b></center>
        </div>
            <form action="" method="post" >{% csrf_token %}
            <font color=#000000 size="3"> 
                <input id="id_pk_post_add" type="hidden" maxlength="1" name="pk_post" type="text">
                <input type="hidden" value="1" maxlength="1" name="post_request" type="text">
                <div style="width:100%; height:55%;">
                <label for="id_description_post" style="display:table; margin-top:0px; padding-left:13px;">Description :<br></label><textarea id="id_description_post_id" maxlength="9999" name="description_post" style="resize:none; font-size: 12pt; width:100%; height:90%; border:solid 2px 9999FF" autofocus onkeyup="enableField(this.form,this.value)" type="text"></textarea><br>
                </div>
                <div style="width:100%; height:6%;">
                <label for="id_start_date" style="display:table; text-align: center;">Start date : </lable><input type="text" name="start_date" id="datetimepicker" style="width:26%; height:120%; border:solid 2px 9999FF"readonly/>&nbsp;&nbsp;&nbsp;      
                <label>End date : </label><input type="text" name="end_date" id="datetimepicker2" style="width:26%; height:120%; border:solid 2px 9999FF"" readonly/>
                </div>
                <div style="width:100%; height:10%;">
                <p align="left" style="padding-left:23px;"><label>Priority : </label>
                <select method="post" name="priority_post" style="border:solid 2px 9999FF">
                       <option value="1" id="id_priority_post" name="priority_post">High</option>
                   <option value="2" id="id_priority_post" name="priority_post">Medium</option>
                   <option value="3" id="id_priority_post" name="priority_post" selected="selected">Low</option>
                </select></p>
                </div>
                <div style="width:100%; height:23%;">
                <center><input type="submit" class="button_add" name="bttnsubmit" value="Add" ONCLICK="window.location.href='/'" disabled="true" style="height:30px; width:80px; border:solid 2px 9999FF" >&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                <a href="" ONCLICK="PopUpHide()" style="color: #2E2EFE">Cancel</a></center>
                </div>
            </font>
        </form>
    </div>
</div>

And to call this function, you would use the following:

<div style="background:; width:33%; float:left;">
    <table id="table1" border="0" cellpadding="4" cellspacing="0" align="center" width="99%">
        <thead>
            <tr >
                <th><div id="b-container">
                    <a href="javascript:PopUpShow(&quot;Add problem item&quot;, 1)"><center><font face="Michroma" color="#FF2F2F">PROBLEMS</font> <font face="Michroma" color="#FFFFFF">ADD</font></center></a>
                    </div>

                </th>
            </tr>
        </thead>
</table>

Question: I need the popup window (HTML text) to be placed inside the JavaScript function because when I start the page, it shows me the popup and hides it quickly. But I only want the popup to show when the function is called. How can I achieve this?

P.S. I tried putting the text in document.write but something didn't work right =)

Answer №1

My recommendation is to give this a shot:

<a onclick="PopUpShow(&quot;Add problem item&quot;, 1)"><center><font face="Michroma" color="#FF2F2F">PROBLEMS</font>&emsp;<font face="Michroma" color="#FFFFFF">ADD</font></center></a>

as opposed to:

<a href="javascript:PopUpShow(&quot;Add problem item&quot;, 1)"><center><font face="Michroma" color="#FF2F2F ">PROBLEMS</font>&emsp;<font face="Michroma" color="#FFFFFF">ADD</font></center></a>

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

What could be causing issues with mysqli connection to the database?

Here is the content of my connect.php file: $mysql_hostname = "localhost"; $mysql_username = "root"; $mysql_password = "xxxxxxxx"; $mysql_database = "marrybrown_clean"; $bd = mysqli_connect ($mysql_hostname, $mysql_username, $mysql_password) or die (&apos ...

Error encountered: LIBUSB_ERROR_NOT_SUPPORTED in the node escpos program

When attempting to print with a thermal printer using the node-escpos module, everything works well on Linux but I encounter an error on Windows. The error message reads: LIBUSB_ERROR_NOT_SUPPORTED. Error: LIBUSB_ERROR_NOT_SUPPORTED at Device.usb.Devi ...

Navigating Through the DOM with Selenium using XPath Axes

Currently, I am developing Selenium tests for a dynamic web page. Within this section of code, I am extracting data from an Excel sheet and verifying if a specific element exists on the webpage. I have annotated the critical part of the code with comments ...

How can I reverse the names displayed in ng-repeat when I click?

When utilizing the orderby filter in angularjs, I want to be able to sort the data only when the button is clicked. If the button is not clicked, the sorting order should not be displayed. <tr ng-repeat="tools in toolsfilter | orderBy:orderByField:reve ...

Guide on Adding Tawk.to Widget to Your Next.JS Website

I followed the instructions on their @tawk.to/tawk-messenger-react plugin documentation, but I am still facing issues. I created a component named /components/Chat.js import TawkMessengerReact from "@tawk.to/tawk-messenger-react"; export defaul ...

Removing single quotes and replacing them with spaces when passing data from JavaScript to MySQL

I'm currently focused on JavaScript using Hapi.js in my role at the company. My main task involves retrieving data from MongoDB and transferring it to a MySQL database. The challenge arises when dealing with data that contains single quotes within th ...

The dependency path in the package.json file contains all the necessary files

I recently developed a JavaScript package and here is the configuration in my package.json: { "name": "packageName", "version": "1.0.0", "description": "Description of the package", " ...

Initiate the SVG animation upon entering the viewport

I'm struggling to initiate the animation when it enters the viewport. I've looked through previous questions on stack overflow, but I can't seem to customize the JS for my specific requirements. My latest attempt was to start the pink line&a ...

CSS - Absolute positioning appears to be slightly choppy in Microsoft Edge

I have successfully implemented a slip scrolling function to reveal/hide a fixed logo on scroll, but I am facing some issues with Microsoft Edge browser. While testing in various browsers, everything works smoothly except for Microsoft Edge. In this brows ...

"Encountering an 'Unexpected string' error when trying to implement a

$('.star').mouseover(function (){ var starIndex = $(this).index()1; $(this).parent().css("background-position", "0 -" + (32 * starIndex) + "px"); }); $('.star-rating').mouseout(function (){ var originalResult = $(this).attr ...

Having an issue with transmitting information to the database using ajax and Laravel

I am currently working on creating a drag and drop list that can be sorted. Each time an element is dropped into a new area, the order of the list should change accordingly. I am implementing this using AJAX and Laravel, but encountering an error when drop ...

What is the best method for styling the "body" of multiple pages in a React.js application to prevent them from overlapping?

Hello everyone, After attempting different approaches in numerous ways, I have turned to the experts here who are sure to have the answer to this simple problem. The issue at hand is that when I try to apply background images and other properties to the ...

``Only Firefox supports jQuery animations, all other browsers fail to render them properly

This particular issue is a bit complex to articulate, so I'll begin by providing the code and then proceed to elaborate on the problem as best as I can. I'm assuming that you've already compared the results in Firefox and other browsers. He ...

What is the best way to distinguish a particular item in a <select> element and include a delete button for each row using jQuery?

1.) I've set up a nested table and now I want to ensure that when the 'Delete' button within the child table is clicked, its corresponding row gets deleted. 2.) I have a <select> tag. The issue is how can I implement validation to che ...

Transforming HTML-encoded JSON into JSON format with BeautifulSoup

Seeking a solution with parsing raw HTML from the bandsintown website using beautifulSoup to access a JSON embedded in a script, particularly the "eventsJsonLd" key in the script section of the page source: "jsonLdContainer":{"eventsJsonLd":[{"@context":" ...

Ways to make a jsonp request without including the 'callback' in the URL

I've been working on retrieving information from an Icecast Radio station using their API, which offers the status-json.xsl endpoint to access this data. Despite the format being in xsl, I suspect it returns a JSON file. However, I've encountere ...

Error with Husky during precommit:

I've upgraded to the latest version of yarn and now I'm setting up Husky in my project. Here is the content from .huskyrc.json: { "hooks": { "pre-commit": "lint-staged", "pre-push": "npm run ...

Encountered a problem while rendering the app: [TypeError: Unable to assign a value to the property 'content' since it is undefined]. Implementing Express with

My experience with res.render is flawless: res.render('main', function(err, html){ // Displays '<html></html>' from 'views/main.html' console.log(html); }); However, the situation changes when it comes to ...

Unable to find app.get in node.js

Within my app.js file, I have the following snippet... var app = module.exports = express(); In another JavaScript file named register.js, I utilize the get method to display a page like so... var module = require('../app'); module.app.get(&a ...

When incorporating script tags in React, an "Unexpected token" error may arise

I am in the process of converting my website to a React site, but I am encountering an issue with the script tags not working. It keeps showing an unexpected token error. Here is the code snippet: <div className="people"> How many people are you ...