Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Web Programming > JavaScript > Javascript How-To
|
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 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 January 20th, 2005, 01:53 AM
Registered User
 
Join Date: Jan 2005
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default Remove value of dropdown list when textbox changed

Hi,

I have values gathered from database, for the dropdown menu.
For example:
A - 5
B - 10
C - 100
And there is a textbox which value will change the dropdown list.
If user fill in the textbox, the dropdown menu should changed accordingly.
For example if user choose 1, the dropdown list will be : A, B, C
However if user fill in 11, the list will be : C (A and B removed)

Is there any javascript code able to do this.
Thanks.
 
Old January 20th, 2005, 07:08 AM
Friend of Wrox
 
Join Date: Oct 2004
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 sn00pyg4rfi3ld
Since your dropdownlist is populated from the database,if you want your requirements to be fullfill then it's not a good idea to bind all the options on the server(Think when user enter 30 then all the options with values less than 30 has removed, Now again user enter the value 2 Then it must show all the options with values equalto or greater than 2 )
So i do feel that it's better to put their those values in Array on the client side,now you can achieve ur requirement.
For example, Try this code
Hope this will help you
<script>
arrOptionval=new Array("1","2","3","4","5","6","7","8","9","10","11 ","12","13","14","15","16","17","18","19","20","21 ","22","23","24","25","26")
arrOptionname=new Array("A","B","C","D","E","F","G","H","I","J","K", "L","M","N","O","P","Q","R","S","T","U","V","w","X ","Y","Z")

function pageonload()
{
var opt
selectobj=document.getElementById("selectbox")
for(i=0;i<arrOptionval.length;i++)
{
   opt=new Option(arrOptionname[i]+" ",arrOptionval[i])
  selectobj[i]=opt
}
}


function textChanged(obj)
{

selectobj=document.getElementById("selectbox")
total=selectobj.length

for(i=0;i<=total;i++)
{
selectobj[total-i]=null
}

indexval=0
for(i=0;i<arrOptionval.length;i++)
{val1=parseInt(arrOptionval[i])
 val2=parseInt(obj.value)
  if(val1>val2){
     opt=new Option(arrOptionname[i]+" ", arrOptionval[i])
    selectobj[indexval]=opt
    indexval++;
  }
}


}



</script>
<body onload="pageonload()">
<input type=text id=inval onblur="textChanged(this)">
<select id="selectbox" size=10 multiple>
</select>
<body>

Cheers :)

vinod





Similar Threads
Thread Thread Starter Forum Replies Last Post
Dual dropdown lists, add and remove Endelee Classic ASP Basics 1 May 4th, 2007 03:31 AM
Data from Dropdown List to TextBox caterpillar General .NET 1 July 10th, 2006 06:05 AM
fill dropdown list with items when parent list isaac_cm Pro PHP 1 July 10th, 2006 05:41 AM
using textbox keypress/text changed bazookajoe76 C# 5 October 10th, 2004 12:03 AM





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