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:
<% 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:
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:
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,
robertmacedonia