Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

dropdown value??

Status
Not open for further replies.
Apr 4, 2010
2
0
0
US
hi everyone:
I am very new to javascript but have a complicated situation...
I have a picklist and was wondering if it is possible to lock or disable a picklist value in javascript after the value is selected.

Also, the picklist rerenders the table to show other controls on the form.

For example:

Picklist Values
A
B
C
D

IF A is selected then a checkbox control shows up on the form and would like A now to be disabled.

That would leave B,C,D as options in the picklist and will have the checkbox present that was assoicated with A.

Any one of any exmaples of this...or if anyone can point me to how would i search for examples of this...
Thank you
etechcareers
 
Here is an example.
Hope this helps.

~Ron

Code:
<html>
<title>Test</title>
<head>
<script>
function doStuff(oElem){
	//Selected value
	var sValue = oElem.value;

	
	//Iterate through options, remove the value that is selected
	var oOptions = oElem.options;
	for (var i =0;i<oOptions.length;i++){
		if (oOptions[i].value==sValue)
			oElem.removeChild(oOptions[i]); 
	}

	//Create an input element
	var oInput = document.createElement('input');
	    oInput.type="checkbox";
	    oInput.name=sValue;
	    oInput.value=sValue;

	//Create some text and a line break
	var oText = document.createTextNode('I have selected '+sValue);
	var oBR = document.createElement('br');	

	//Get the container box and append everything there
	var oDiv = document.getElementById('controls');
	oDiv.appendChild(oInput);
	oDiv.appendChild(oText);
	oDiv.appendChild(oBR);	


}
</script>
</head>


<body>
<form>
	<div id="controls">

	</div>

	<select id="a" onchange="doStuff(this)">
		<option value="1">1</option>
		<option value="2">2</option>
		<option value="3">3</option>
	</select>


</form>


</body>


</html>

typedef map<GiantX,gold, less<std::shortestpathtogold> > AwesomeMap;
 
Why remove it altogether and not just disable the selected <option> instead:

Less code, and the options remain should you need to re-enable them. Instead of having to refresh the page to get them back.
Code:
<script>
function doSomething(mysel){
var index=mysel.selectedIndex;
mysel.selectedIndex=0;
mysel.options[index].disabled=true;
}
</script>

<select onChange="doSomething(this);">
<option value="0">Choose One...</option>
<option value="1">One</option>
<option value="2">Two</option>
<option value="3">Three</option>
<option value="4">Four</option>
</select>

Tested on FF and IE.

----------------------------------
Phil AKA Vacunita
----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.
 
Thank you to the both of you for taking the time out and helping me out....
I really appreciate it and I always love less code...
Thanks
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top