Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Web Programming > JavaScript > Javascript How-To
Password Reminder
Register
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
Javascript How-To Ask your "How do I do this with Javascript?" questions here.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Javascript How-To section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old June 6th, 2007, 12:29 PM
Friend of Wrox
 
Join Date: Aug 2006
Location: norcross, Ga, USA.
Posts: 107
Thanks: 0
Thanked 0 Times in 0 Posts
Default How to avoid page refreshing

hi all

I am trying to solve this problem for a while. but not yet done

I dont know javasxript, but i have to use that in my application for the below task

I have 3 listboxes in my page, and have them loaded with data

I have 3 checkboxes also under each listbox

What i want to do is, when checkbox1 is checked, listbox1 items all get selected

When checkbox is unchecked, the items get deselected.

Also i am trying so that, while the checkbox is checked and the items are selected, if the

user selects a particular item in listbox, the checkbox check should get removed.

The same thing i want to accomplish for the 3 listboxes

All these i have done in code behind, which causes page refreshingI am trying to do them in javascript

I hve tried the below code, but its not getting any result, the listbox items are not being selected
Code:
function selectChange(checkBox1)

{
var listBox = document.getElementById('lstAccounts');

if(checkBox1.checked)
{
for (var i=0; i<listBox.options.length; i++)
{
listBox.options[i].selected = true;
}
}
else
{
for (var i=0; i<listBox.options.length; i++)
{
listBox.options[i].selected = false;
}
}
}

<asp:ListBox ID="lstAccounts" runat="server" Height="125px" Width="135px" SelectionMode="Multiple" AutoPostBack="True"></asp:ListBox> <input id="Checkbox1" type="checkbox" onclick="selectChange(this)" />Check All
Hope someone can help me in this

Thanks
Reply With Quote
  #2 (permalink)  
Old June 12th, 2007, 02:11 AM
Friend of Wrox
 
Join Date: Oct 2004
Location: delhi, delhi, India.
Posts: 553
Thanks: 0
Thanked 1 Time in 1 Post
Send a message via MSN to vinod_yadav1919 Send a message via Yahoo to vinod_yadav1919
Default

Hii Sarah lee!!


*** You are using asp.net 2.0 or something else.
*** Also ensure that the html code rendered by the ASP.Net Framework,i.e ListBox ID and other controls id is correct as you were writing in ur js code.
Plz check the following working code.


<script language="javascript">
function selectChange(checkBox1)

{
var listBox = document.getElementById('lstAccounts');

if(checkBox1.checked)
{
for (var i=0; i<listBox.options.length; i++)
{
listBox.options[i].selected = true;
}
}
else
{
for (var i=0; i<listBox.options.length; i++)
{
listBox.options[i].selected = false;
}
}
}
</script>
<input type=checkbox id=checkbox1 onclick="selectChange(this)">
<select name="lstAccounts" id="lstAccounts" multiple>
<option value=1>1</option>
<option value=1>11</option>
<option value=1>12</option>
<option value=1>123</option>
<option value=1>13</option>
</select>
Hope this will help you

Cheers :)

vinod
Reply With Quote
  #3 (permalink)  
Old June 12th, 2007, 07:51 AM
Friend of Wrox
 
Join Date: Aug 2006
Location: norcross, Ga, USA.
Posts: 107
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi

Thank you for your response

I got the javascript to work
But it lead to another issue
I am calling javascript frm server side
What happens is as the listbox 1 get populated, 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

Thank you very much for your help so far


Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Problem with refreshing the page fozia_izhar .NET Framework 1.x 1 March 24th, 2007 02:18 PM
page not refreshing Bill Crawley ASP.NET 2.0 Basics 8 February 28th, 2007 11:39 AM
refreshing XML withour refreshing the page sasidhar79 XML 1 January 12th, 2005 05:16 AM
Problem In refreshing a page. zaeem Classic ASP Components 2 November 4th, 2003 12:42 AM



All times are GMT -4. The time now is 09:46 AM.


Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.