1

I am using selectable jquery in my jsp page. On submitting the form, the string should pass as parameter to servlet.

$(function() {
    $("#selectable").selectable({
        stop: function() {
            var result = $("#select-result").empty();
            $(".ui-selected", this).each(function() {
                var index = $("#selectable li").index(this);
                result.append(" #" + (index + 1));
            });
        }
    });
});

I want var result as value in <input type="hidden" id="select-result" value=""/>

Form -

<form action="XYZServlet" method="get">
 <input type="text" id="from" name="from">
 <input type="hidden" id="select-result" value="">
 <input type="submit" value="Submit"/>
</form>

How can I do this?

2
  • could you please post your form code. Commented Nov 12, 2015 at 9:14
  • added my form code too Commented Nov 12, 2015 at 9:18

2 Answers 2

1

How about:

$(function() {
    $("#selectable").selectable({
        stop: function() {
            var result = $("#select-result").empty();
            $(".ui-selected", this).each(function() {
                var index = $("#selectable li").index(this);
                result.append(" #" + (index + 1));
            });
        $("#select-result").val(result);
        }
    });
});
Sign up to request clarification or add additional context in comments.

2 Comments

i changed input type as text & found out value = [object Object]
Try casting the value [object Object] into String
0

You just need the index, right?

$(function() {
    $("#selectable").selectable({
        stop: function() {
            var result = $("#select-result").empty();
            $(".ui-selected", this).each(function() {
                var index = $("#selectable li").index(this);
                result.append(" #" + (index + 1));
                document.getElementById("my").value = index;
            });      
        }
    });
});

You can view the Value as index(selected item) - <input type="text" id="my" value=""/>

I hope this will work :)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.