It appears you have not yet registered with DEVPPL. To register please click here... (it's fast, easy and free!)

Forum

Log In Sponsors
Board index Programming JavaScript Forum

Javascript posting strange commas

Javascript posting strange commas

Postby aDameToKillFor on Fri Mar 18, 2011 10:54 pm

Hi, I have one script that should check for a couple of checkboxes which one of them is checked, and store their values, then post them back to the controller(it's an MVC application, but that is not that much important). I am doing this using an additional hidden input field, like this:


Code: Select all
<% for(int i = 0; i < Model.Languages.Count; i++)
              { %>
            <input name="applang" type="checkbox" value="<%: Model.Languages[i].languageID %>" />
             <input type="hidden" id="hiddenFieldDemo" name="hiddenFieldDemoName" />
            <%: Model.Languages[i].name.ToString() %><br />

            <%} %>


here's the script:

Code: Select all
function get_check_value() {

        var hiddenFieldDemoVar = document.getElementById('hiddenFieldDemo');

             for (var i = 0; i < document.addLangForm.applang.length; i++) {

                 if (document.addLangForm.applang[i].checked) {
                        hiddenFieldDemoVar.value = hiddenFieldDemoVar.value + document.addLangForm.applang[i].value + '  ';
                 }

         }


So, now when I try to get the values in the backend code, like this:

Code: Select all
string hiddenFieldDemoStringArray = Request.Form["hiddenFieldDemoName"];


I get just three comma values, i.e. - ",,,". I should probably mention that there are 4 checkboxes and currently I am selecting just one of them, the first one, so I expect this string hiddenFieldDemoStringArray to get the value - "1". But, I get the commas instead.

Any help would be appreciated.

Kind regards,
aDameToKillFor
aDameToKillFor
 
Posts: 1
Joined: Fri Mar 18, 2011 10:50 pm

Who is online

Users browsing this forum: No registered users and 8 guests