954,551 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Listbox help needed!!

Hi everybody

I use a javascript to select and deselect items in a listbox depending on checkbox selection

The problem now i have is, i am calling the javascript from server side

What happens is as the listbox 1 get populated, and selected with checkbox selection in my application,
i have a button which refreshes the page thereby populating listbox2, with reference to the items selected in listbox1

So what is happening is,
- the user selects checkall-- all items get selected
- the user hits the refresh button -- all the items deselected and also checkbox is marked unchecked

Hope you can understand my issue
Please help me to fix this dilemma
Thanks to all

Sarah Lee
Light Poster
45 posts since Sep 2006
Reputation Points: 10
Solved Threads: 0
 

The application that your working on.. is it a web application? and i really can't understand what the error is.. May be you can post some code and explain it with a screen shot.

arjunsasidharan
Practically a Posting Shark
826 posts since Aug 2006
Reputation Points: 347
Solved Threads: 13
 

Thanks for your response
it is a web application
The code i am using is

function onChange(checkBoxRef,listboxId)
{

var listboxRef = document.getElementById(listboxId)

if(checkBoxRef.checked)
{


for (var i=0;i<listboxRef.options.length;i++)


{

listboxRef.options[i].selected = true;

}
}
else
{

for (var i=0; i<listboxRef.options.length; i++)

{

listboxRef.options[i].selected = false;

}
}
}

function removeCheck(checkboxId)
{
document.getElementById(checkboxId).checked = false;
}


And in code behind i am using

lstAccounts.Attributes.Add("onChange", "Javascript:removeCheck('" + chkAll.ClientID + "');")
chkAll.Attributes.Add("onClick", "javascript:onChange(this, '" + lstAccounts.ClientID + "');")


When the page is refreshed by a button click, all the items are deselcted and the checkbox mark is also gone
Any ideas, what is wrong with my code?

Thank you very much

Sarah Lee
Light Poster
45 posts since Sep 2006
Reputation Points: 10
Solved Threads: 0
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You