A guide on how to showcase an alert message box with a radio button using JavaScript

<html>    
  <body>
    <button id="popup-btn">Click for Popup</button>
  </body>
  <script type="text/javascript">
      var popUpContent = $('<div><input type="radio">Option A<br><input type="radio">Option B<br><input type="radio">Option C</div>');
      $("#popup-btn").click(function() {
        popUpContent.dialog();
      });
    </script>
  </body>  
</html>

Answer №1

It appears that the jQuery and ui imports may be missing from your code

$(function() {
  var popUpList = $('<div><input type="radio">A<br><input type="radio">B<br><input type="radio">C</div>');
  $("#dialog").click(function() {
    popUpList.dialog();
  });
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<link href="//code.jquery.com/ui/1.11.4/themes/smoothness/jquery-ui.css" rel="stylesheet" />
<script src="//code.jquery.com/ui/1.11.4/jquery-ui.js"></script>

<button id="dialog">Show Popup</button>

Answer №2

In order to create a jQuery UI object, you need to capture the page load event.

Here is one way to achieve this:

<script type="text/javascript>
    $(document).ready(function() {
     var popUpList = $('<div><input type="radio" name="a">A<br><input type="radio" name="a">B<br><input type="radio" name="a">C</div>');
        $("#dialog").click(function () {
            popUpList.dialog();
        });
    });
</script>

Alternatively, you can also use:

<script type="text/javascript>
  $(function(){
    //  This code block will be executed once jQuery has finished loading and is ready for use.
  });
</script>

Answer №3

Kindly attempt the following:

 popUpList.dialog("open");

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

How can a JavaScript array be transmitted as a JSON value?

Is there a method to pass a JavaScript array as a JSON variable in my AJAX query? ...

Transferring a user's data to a different page for editing purposes

On my admincustomers.php page, I am displaying a table of user data. When I select the EDIT option for a specific user, I want to navigate to editusers.php and display that user's information. However, I am facing an issue in carrying over the custome ...

Demonstrate HTML and CSS integration through the use of the http.get method

In an attempt to create an iframe-like solution, I am using an http.get call to retrieve a site as an object containing HTML and CSS. The issue arises when using <link> tags because the CSS path is obtained from an external source, causing the HTML t ...

Applying CSS classes to a custom AngularJS directive: A step-by-step guide

Need to have a CSS class called tab for the nav HTML element, which will be used as a directive: <nav tab></nav> The expected interpretation is: <nav class="tab"> <a></a> <a></a> <a></a> ...

Expanding worldwide mixin in Nuxt.js

Currently, I am working with Nuxtjs version 2.15.7 and have a mixin file structured like this: utils.js : import Vue from "vue" if (!Vue.__utils__) { Vue.__utils__ = true Vue.mixin({ data(){ return{ ... } }, ...

Vow failing to function as intended

I have encountered an issue with performing a nested query in MySql, saving the result to a variable, and sending it over http. The problem is that the program always executes console.log("test 2:"+rpsData); before the query finishes. Despite attempting ...

What is the best way to store text including line breaks in a database?

Starting out as a new web developer, I am eager to create my own web-based text editor application and require some advice. How can I store text with line breaks in a database? I am considering using MongoDB. Additionally, I am curious about the databases ...

Certain HTML elements on the webpage are not functioning properly when attempting to incorporate a div tag

One of the challenges I'm currently facing is that the links for HOME and ABOUT ME in the header section are not accessible when the 'data' div is added. Strangely, the DOWNLOAD and CONTACT ME links still work fine. This issue seems to be oc ...

When the content div is clicked within the overlay div, the popup will also close

I want to design a pop-up that features a container with a black background and some opacity, where the content of the popup is placed inside. Here's what I have in mind: <button (click)="showPopup = !showPopup">Open popup</button& ...

Exploring Objects using the for-in loop in ReactJS

This code is written in Reactjs. I am attempting to iterate through and print object data, but I keep encountering an error --> TypeError: Cannot read properties of undefined (reading 'state'). Could someone please help me identify what I am d ...

Updating the subject line in Outlook emails

Can you change the subject of an email that someone receives in Outlook? I believe it might be possible. Perhaps similar to how user agents are used for browsers? I'm fairly new to emails and my online searches have not been helpful despite spending ...

How can I retrieve the number of followers for a specific user ID using Laravel?

I am working with Laravel and jQuery integration public function getFollower(Request $request){ $userId = $request->get('user_id'); $artists = DB::table('artists') ->select('artists.id', 'artis ...

Encountering an error: [nsIWebProgressListener::onStatusChange] when utilizing jQuery AJAX within a click event?

Greetings! I am currently learning how to implement AJAX with jQuery to load an HTML document into a div element within another HTML document. Here is the approach I am using: function pageload() { $.ajax({ url: 'Marker.aspx', ...

Are there various rules for validating each form element?

I have a specific requirement to apply individual validation rules to each form element. For example: The "title" field only allows letters (both uppercase and lowercase) and spaces The "owner" field only allows letters (both uppercase and lowercase) an ...

jQuery Validate Custom Function - Exceeding the Minimum Threshold

I came across a post that explains how to implement jquery validation for values greater than the minimum: jquery validation for more than min value The only tweak I need is that the field is not mandatory. Even after adjusting the rules as shown below, i ...

Using JavaScript to retrieve comma-separated values depending on a specific condition

Hey there, I am encountering a problem with filtering out values from an array of objects. Essentially, I have an array of objects const arr = [ { "id": null, "name": null, "role": "Authorized ...

I'm encountering an issue with automatically updating content on a webpage

I am currently working on a webpage that refreshes its content automatically to display the most up-to-date data from the database. Here's the JavaScript code I'm using: setInterval(function() { $("#status").load('refresh.php'); }, ...

What is the best way to define one API route that accommodates two different query combinations?

Is it possible to define 1 API route with 2 different query combination options? We have 2 routes: GET /api/v1/resource?filter=byName&key=restaurant&city=chicago GET /api/v1/resource?filter=byLocation&lat=34&long=78 In soaJS, schema ...

Why isn't setInterval set to a duration of one thousand milliseconds?

While trying to use some code from w3schools, I noticed that the setInterval in the example is set to 5 instead of 5000. Shouldn't it be in milliseconds? If not, how can I speed up this animation? When I try reducing it to decimals like 0.01, the anim ...

Is there a way to hide the <v-otp-input> field in a Vue.js application?

For more information, please visit https://www.npmjs.com/package/@bachdgvn/vue-otp-input <script> export default { name: 'App', methods: { handleOnComplete(value) { console.log('OTP completed: ', value); } ...