Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / JScript / September 2003

Tip: Looking for answers? Try searching our database.

Reset listbox select items to selectedindex=0

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
berrucho - 02 Sep 2003 13:22 GMT
Hi!

I have several vb.net listbox with several items in a search page. Users
filter their search criteria by selecting items. If all
listboxes.SelectedIndex=0 then the search retreives all items.

Requirement:

A client-side button to reset all listboxes to selected index = 0

How to do it in javascript?

tried:

<head>
function reset()
{
document.Form1.listbox1.selectedIndex = 0;
document.Form1.listbox2.selectedIndex = 0;
...
}
</head>

and onclick of the button ... onClick="reset()"

but I get an error "object does not support this method or property..."

please help

thanks

berrucho
Vjekoslav Begovi? - 02 Sep 2003 14:44 GMT
> Hi!
>
[quoted text clipped - 7 lines]
>
> How to do it in javascript?

Check this sample:

<html>
<head>

<head>
<script type="text/javascript">
function resetLists(){
document.forms["form1"].elements["sel1"].selectedIndex = 0;
document.forms["form1"].elements["sel2"].selectedIndex = 0;
}
</script>
<body>
<form id="form1">
<select name="sel1">
<option value="0">None</option>
<option value="1">One</option>
<option value="2">Two</option>
</select>
<select name="sel2">
<option value="0">None</option>
<option value="1">One</option>
<option value="2">Two</option>
</select>
<button onclick="resetLists()">Reset lists</button>
</form>
</body>
</html>

Or, if you want to reset *all* SELECT elements in form1, you could use this
function:
resetLists(){
var selects = document.forms["form1"].getElementsByTagName("SELECT");
for (var i=0; i<selects.length; i++){
selects.item(i).selectedIndex = 0;
}
}
berrucho - 02 Sep 2003 19:28 GMT
Many thank's Vjekoslav
Worked perfectly
I was doing it server side...........
berrucho

> > Hi!
> >
[quoted text clipped - 45 lines]
> }
> }

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.