Wrox Programmer Forums
Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP 3 Classic ASP Active Server Pages 3.0 > ASP Forms
|
ASP Forms As of Oct 5, 2005, this forum is now locked. Please use "Classic ASP beginner" at http://p2p.wrox.com/forum.asp?FORUM_ID=54 or "Classic ASP Professional" http://p2p.wrox.com/forum.asp?FORUM_ID=56 instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP Forms section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old November 1st, 2004, 02:39 AM
Friend of Wrox
 
Join Date: Jun 2004
Posts: 128
Thanks: 0
Thanked 0 Times in 0 Posts
Default How to restrict the maximum number of possible sel

Hi,

How to restrict the maximum number of possible selections in a multiple list box or drop-down list in ASP or javascript.
In my application i have to restrict the maximum selection must be greater than 3 from the dropdown list.

Regards
Lily

 
Old November 1st, 2004, 06:06 AM
Friend of Wrox
 
Join Date: Sep 2003
Posts: 363
Thanks: 0
Thanked 1 Time in 1 Post
Default


I think there is no specific property to limit selection.

You can do in javascript.

Loop thru all items in the select control and increment the counter for each one selected.
Test the couter with your reqd value and display an alert.


------------
Rajani

 
Old November 1st, 2004, 07:29 AM
Friend of Wrox
 
Join Date: Jun 2004
Posts: 128
Thanks: 0
Thanked 0 Times in 0 Posts
Default

How to write the script, can u give the code, plz?

 
Old November 1st, 2004, 09:25 PM
Friend of Wrox
 
Join Date: Sep 2003
Posts: 363
Thanks: 0
Thanked 1 Time in 1 Post
Default

Hi,


<form name="frm1">
<select name="sel1" id="sel1" multiple>
<option value="1">One</option>
<option value="2">Two</option>
<option value="3">Three</option>
<option value="4">Four</option>
<option value="5">Five</option>
</select>

<input type="button" value="Check" onclick="chkData()">
</form>


<script language="javascript">
function chkData(){
var test=0;
    for(i=0;i<parseInt(frm1.sel1.options.length);i++){
        if(frm1.sel1.options(i).selected){
            test++;
        }
    }
    if(test>3){
        alert("You can select maximum of 3 options only");
        return false;
    }
}
</script>



----------
Rajani

 
Old November 2nd, 2004, 01:11 AM
Friend of Wrox
 
Join Date: Jun 2004
Posts: 128
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks a lot Rajani.

----------------------------------------------------------------
Lily







Similar Threads
Thread Thread Starter Forum Replies Last Post
Maximum Number of Controls? Aaron Edwards Visual Studio 2005 0 March 3rd, 2007 06:04 PM
maximum number of prefixes? gumgak ASP.NET 1.0 and 1.1 Basics 5 February 13th, 2006 09:56 AM
How to restrict the maximum number of possible sel lily611 General .NET 2 November 20th, 2004 01:11 AM
How to restrict the maximum number of possible sel lily611 ASP.NET 1.0 and 1.1 Basics 1 October 30th, 2004 07:57 PM
find maximum number Abhinav_jain_mca SQL Server 2000 4 September 28th, 2004 08:13 AM





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