• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Devaka Cooray
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Tim Moores
  • Carey Brown
  • Mikalai Zaikin
Bartenders:
  • Lou Hamers
  • Piet Souris
  • Frits Walraven

javascript funtion needed for given html option/combo box

 
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi all,
I am new to this java script...
in one select option box i am adding three options named AAA, BBB and CCC
<SELECT size="1" name="cmb1" onChange="myNewFunction(cmb1)">
<option value = "AAA">AAA
<option value = "BBB">BBB
<option value = "CCC">CCC
</SELECT>
now myNewFunction will take this cmb1.
myNewFunction should not allow the user to change the item/value.
what ever is selected in cmb1, it should be there as selected. cmb1 should not allow to select another item/value.
can u pls help regd this issue....
thanks
shalini
 
author
Posts: 15385
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Are you saying once it is selected it can not be changed??
 
Ranch Hand
Posts: 3244
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Speaking of changing....
shalinippriya
your name is not in keeping with our naming policy here at the ranch. Please change your display name to an appropriate name as shown in the policy.
Thanks again and we hope to see you around the ranch!!
 
shalinippriya
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
yes.exactly...
that cmb1 should not allow any other selection.
 
Eric Pascarello
author
Posts: 15385
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
after the onchange
this.disabled=true;
 
shalinippriya
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
meaning disabling the cmb1 itself...
but i need to submit the selected value to the server side.
then if i disable it, i will not take that value.
For sample I have done it for AAA and BBB but when i tried for three items,then i faced problem.
function myNewFunction(FromCombo)
{
//here for some condition i will allow the option to select the other item
// but for some other condition i will not allow the option to select the other item
if(condition1)
{
// i will allow the user to select the option item
}
else if(condition2)
{
// i will not allow the user to select the option item
for(var i = 0; i < FromCombo.options.length;i++)
{
if(FromCombo.options[i].value == "AAA")
{
document.form.FromCombo.options[i].value = "BBB";
document.form.FromCombo.options[i].text = "BBB";
}
else
{
document.form.FromCombo.options[i].value = "AAA";
document.form.FromCombo.options[i].text = "AAA";
}
}
}
}
 
Eric Pascarello
author
Posts: 15385
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Look at the following and see if this is what you want to happen.

[ November 18, 2003: Message edited by: Eric Pascarello ]
 
shalinippriya
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
no ..I think it's not working for me
<script>
var allowSelection = true;
var pickedSelection = 0;
function limitIt()
{
if(document.form.T1.value == "" )
{
allowSelection = false;//allow the user to select the item in cmb1
return false;
}
else ////don't allow the user to select the item in cmb1
{
alert("cmb not selectable ");
if(allowSelection)
{
pickedSelection = document.form.cmb1.selectedIndex;
allowSelection = false;
}
return false;
}
}
</script>
<SELECT size="1" name="cmb1" onChange="limitIt()" >
<option>1</option>
<option>2</option>
<option>3</option>
</SELECT>
 
Eric Pascarello
author
Posts: 15385
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
true allows a person to select
false does not allow a person to select
 
Your mind is under my control .... your will is now mine .... read this tiny ad
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic