0

I'd like to allow end users to provide a comma separated string in a text box, and have that string be split on the comma and returned to the controller as a list of strings via a form submission. Here's the code I have so far:

var me = this;

        var $checkNbrInput = $('#checkNumberInput');

        var checkNbrs = $checkNbrInput.val();
        var checkNbrArrayCleansed = checkNbrs.replace(' ','').split(',');

        me._checkNumberArray.push.apply(me._checkNumberArray, checkNbrArrayCleansed);
        var checkNumberArrayObj = [];

        me._checkNumberArray.map(function(val, i) {
            checkNumberArrayObj[i] = { name: 'CheckSearch.CheckNumbers', value: val };
        });
        console.log(checkNumberArrayObj);
        var paramString = $.param(checkNumberArrayObj);
        console.log(paramString);

        $('.check-numbers').val(paramString); //form value 
        $('#checkNumberCount').text(me._checkNumberArray.length);
        $checkNbrInput.val('');

The paramString being assigned to the .check-numbers form field is being built correctly, however its being bound to the first member of the List and not being split up as separate list members.

What I want on the server side for this List:

('42','67','7899') - 3 list members

What I'm getting

('CheckSearch.CheckNumbers=42&CheckSearch.CheckNumbers=67&CheckSearch.CheckNumbers=7899') - 1 list member.
2
  • var checkNbrArrayCleansed = checkNbrs.replace(' ','').replace(",", "','"); this will have expected output. This can be assigned directly to $('.check-numbers').val("'" + checkNbrArrayCleansed + "'"); Commented Jul 7, 2014 at 16:36
  • Thanks @BhasyakaruluKottakota but that didn't work either. I'm just going to do the string manipulation and build the list on the server side.
    – MickJuice
    Commented Jul 7, 2014 at 18:55

0

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.