Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how do i create a prompt in javascript with 3 checkboxes/radio buttons as choices?

How do I create a javascript prompt box where you have to select 1 of 3 choices? I'm looking to do something similar to a html form's radio buttons except within a javascript prompt.

like image 845
Incognito Avatar asked May 16 '11 23:05

Incognito


People also ask

What is the difference between using radio buttons and checkboxes on a form?

Checkboxes and radio buttons are elements for making selections. Checkboxes allow the user to choose items from a fixed number of alternatives, while radio buttons allow the user to choose exactly one item from a list of several predefined alternatives.

What are prompts in JavaScript?

The prompt() method is used to display a dialog box with an optional message prompting the user to input some text. It is often used if the user wants to input a value before entering a page. It returns a string containing the text entered by the user, or null.

How do you ask for input in JavaScript?

In JavaScript, we use the prompt() function to ask the user for input. As a parameter, we input the text we want to display to the user. Once the user presses “ok,” the input value is returned. We typically store user input in a variable so that we can use the information in our program.


2 Answers

You could use jQuery and do a 3 button dialog(). Check out this working jsFiddle demo:

$("#dialog").dialog({

    autoOpen: true,
    buttons: {

        Yes: function() {

            alert("Yes!");
            $(this).dialog("close");
        },
        No: function() {

            alert("No!");
            $(this).dialog("close");

        },
        Maybe: function() {

            alert("Maybe!");
            $(this).dialog("close");
        }

    },
    width: "400px"

});
like image 125
Code Maverick Avatar answered Sep 22 '22 04:09

Code Maverick


This can't be achieved natively as .prompt(). This functionality requires more advanced JS. Here are some libs to mess with:

  1. jQuery UI (dialog)
  2. jQuery Tools - Overlay

Could be more adequate ones out there. Been a while using such stuff

like image 42
Z. Zlatev Avatar answered Sep 21 '22 04:09

Z. Zlatev