I have problems with javascript in ASP.NET.
I modify a listBox, with add and remove command using javascript.
Now I have to use the data of the list in the code behind. How can I pass this data to the server? Can I use json?
Here is the code. I can't use hiddenField because of the remove.
<asp:listbox ID="SubCat" runat="server" ></asp:listbox>
<input type=button onClick="addOption(SubCat)"; value='Add'>
<input type=button onClick="removeOptions(SubCat)"; value='Remove Selected'>
<input type=button onClick="removeAllOptions(SubCat)"; value='Remove All'>
<script type="text/javascript">
function removeAllOptions(selectbox) {
var i;
for (i = selectbox.options.length - 1; i >= 0; i--) {
selectbox.remove(i);
}
}
function removeOptions(selectbox) {
var i;
for (i = selectbox.options.length - 1; i >= 0; i--) {
if (selectbox.options[i].selected)
selectbox.remove(i);
}
}
function addOption(selectbox) {
var txtBox1 = document.getElementById('txForn')
var optn = document.createElement("OPTION");
var t = txtBox1.value;
optn.text = t;
optn.value = t;
selectbox.options.add(optn);
}
</ script>