0

I have this function,

function add_to_team_confirm(a, b) {
    result = window.confirm("Sure?");
    if (result) {
        window.location = "url";
    }
    return result;
}

and I will call this once I will click an anchor tag,

<a href="#" onclick="return add_to_team_confirm(' a ', 'b ');">Add to team</a>

when this is clicked, a prompt will be shown having only two options, OK and Cancel. Now, what I would like is adding another option like, Use Credits, since a feature like using credits is possible in adding a player to the team. Now my question is, is it possible to add another option? And what is the value of that option so that when it is clicked, its value will then be shown and then I can process any process I want once it is clicked. I am not that really good in explaining but I hope you get it. Thanks.

Kyle Macey
  • 8,074
  • 2
  • 38
  • 78
Tsukimoto Mitsumasa
  • 541
  • 4
  • 19
  • 42

2 Answers2

1

Options are very flexible for things like this. Here's a simple pattern for doing this with jQuery:

In your onclick statement:

onclick="handle_team_confirm_click();"

function handle_team_confirm_click() {
    var returnData = add_to_team_confirm(' a ', 'b ');
    var myOptions = {val1 : returnData };
    var mySelect = $('#mySelect');
    $.each(myOptions, function(val, text) {
        mySelect.append(
            $('<option></option>').val(val).html(text)
        );
    });
}

Now you can get the value like this:

$("#mySelect").click(function() {
    $("#mySelect option:selected").val();
});
Wesley
  • 5,381
  • 9
  • 42
  • 65
  • im a bit confused on what you gave. where's the function that i will calling now? – Tsukimoto Mitsumasa Aug 14 '12 at 16:15
  • You can use the top pattern to add an option, or a series of options to the select. The bottom value will get you the value of the selected option after the user has made a choice. You can call this in a simple jQuery .click() event. – Wesley Aug 14 '12 at 16:17
  • is there any other way where i can add another option, still using my function above?what i want is it will still be considered as a result value of window.confirm. – Tsukimoto Mitsumasa Aug 14 '12 at 16:19
  • Sure. I'll modify the answer. – Wesley Aug 14 '12 at 16:23
0

You can try window.showModalDialog

References & useful pages:

[CiteHistory Record]

afourney
  • 1,657
  • 1
  • 12
  • 10