Jump to content

Combo Box


adam84

Recommended Posts

you will need an input with the onchange thing

<input onchange="changeSelect(this.value)" />

 

the changeSelect function must then check if the input is a number(plenty of scripts to find online for that)

and then change the page html using javascript DOM

Link to comment
https://forums.phpfreaks.com/topic/59080-combo-box/#findComment-293541
Share on other sites

Here is a few function that will help you select any option based on the value, text or index

<script language="javascript">

// select an option based on value
function selSelectValue(sel, val){
var op = sel.childNodes;
var selIndex = 0;
for(i=0; i<op.length; i++){
	if (op[i].tagName == "OPTION"){
		if (op[i].value == val) {
			sel.selectedIndex = selIndex;
			i = op.length+1;
		}
		selIndex++;
	}
}
}

// select an option based on text
function selSelectText(sel, val){
var op = sel.childNodes;
var selIndex = 0;
for(i=0; i<op.length; i++){
	if (op[i].tagName == "OPTION"){
		if (op[i].innerHTML == val) {
			sel.selectedIndex = selIndex;
			i = op.length+1;
		}
		selIndex++;
	}
}
}

// select an option based on index
function selSelectIndex(sel, val){
sel.selectedIndex = val;
}
</script>
<select id="sel" name="sel">
<option VALUE="value1">Hotmail</option>
<option VALUE="value2">Gmail</option>
<option VALUE="value3">Yahoo</option>
</select>	
<br />
Text:<br />
<input type="text" id="val" />
<br /><br />
<button onclick="selSelectValue(document.getElementById('sel'), document.getElementById('val').value);">Select by Value</button> enter value1, value2 or value3<br />
<button onclick="selSelectText(document.getElementById('sel'), document.getElementById('val').value);">Select by Text</button> enter Hotmail, Gmail, Yahoo<br />
<button onclick="selSelectIndex(document.getElementById('sel'), document.getElementById('val').value);">Select by Index</button> enter 0, 1, 2

Link to comment
https://forums.phpfreaks.com/topic/59080-combo-box/#findComment-293867
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.