user1421432
user1421432

Reputation: 103

how to add a value onto the url using javascript var

Is there a way to add the select-result on the url when the pop up window appears? The select-result gives the value of the boxes selected and i want to pass the values selected gto a form but i am not ussing a form. can i pass the values ussing the url?

i want to add the selected values like form.php?id=2882,222,22412,23

$(function() {
    $(".selectable").selectable({
        filter: "td.cs",
        stop: function() {
            var result = $("#select-result").empty();
            var result2 = $("#result2");
            $('.ui-selecting:gt(31)').removeClass("ui-selecting");
            confirmation($(".ui-selected").length + " box selected. " + ($(".ui-selected").length));
            function confirmation() {
                var answer = confirm($(".ui-selected").length + " box selected.  " + ($(".ui-selected").length));
                if (answer) {
                    window.open("form.php", "mywindow", "menubar=no,resizable=no,width=650,height=700");
                }
                else {}
            }
            $('#divmsg').html($(".ui-selected").length + " box selected")
            $('#divmsg2').html($(".ui-selected").length)
            if ($(".ui-selected").length > 90) {
                alert("Selection of only 90 boxes allowed");
                $('#divmsg').html($('#divmsg').html() + ",<br><b>Message: Selection of only 90 pixels allowed!!</b>");
                $(".ui-selected").each(function(i, e) {
                    if (i > 3) {
                        $(this).removeClass("ui-selected");
                    }
                });
                return;
            }
            $(".ui-selected", this).each(function() {
                var cabbage = this.id + ', ';
                result.append(cabbage);
            });
            var newInputResult = $('#select-result').text();
            newInputResult = newInputResult.substring(0, newInputResult.length - 1);
            result2.val(newInputResult);
        }
    });
});​

this is the fiddle http://jsfiddle.net/dw6Hf/57/

i have tried

window.open ("form.php?id="+ select-result, "mywindow",....

but it won't work!! any idea??? Thanks in advance ​

Upvotes: 0

Views: 98

Answers (2)

Wiz
Wiz

Reputation: 500

Firstly the fiddle you have posted is broken. But no worries i have fixed it along with the solution at http://jsfiddle.net/paragnair/dw6Hf/61/

I have added the following line:

var selectedIds = $.map($('.ui-selected'),function(a){ return $(a).attr('id');}).join(',');

The above line gets the list of ids for all the elements which have the class ui-selected. Then you can append the variable selectedIds to window.open like so:

window.open("form.php?id=" + selectedIds, "mywindow", "menubar=no,resizable=no,width=650,height=700");

Upvotes: 1

Ryan Kinal
Ryan Kinal

Reputation: 17732

If you're asking what I think you're asking, and selectable does what I think it does, then try this:

window.open("form.php?id=" + $('#select-result').text(), "mywindow", "menubar=no,resizable=no,width=650,height=700");

If that doesn't work, then I've obviously misunderstood your answer. I'd suggest clearing it up, and maybe getting a working example up and running for us to see.

Upvotes: 1

Related Questions