adam84 Posted July 9, 2007 Share Posted July 9, 2007 I want to set my combo to a cetain index and I cannot get it to work. Any ideas? my combo box document.getElementById('companyCB') Link to comment https://forums.phpfreaks.com/topic/59080-combo-box/ Share on other sites More sharing options...
RichardRotterdam Posted July 9, 2007 Share Posted July 9, 2007 I dont get it what do you want exactly can you be more clear or paste some code? Link to comment https://forums.phpfreaks.com/topic/59080-combo-box/#findComment-293344 Share on other sites More sharing options...
adam84 Posted July 9, 2007 Author Share Posted July 9, 2007 All i want to do is have the user enter in a number in a textbox and if they enter in 5, i want to set my combo box to the 5th element. Link to comment https://forums.phpfreaks.com/topic/59080-combo-box/#findComment-293363 Share on other sites More sharing options...
RichardRotterdam Posted July 9, 2007 Share Posted July 9, 2007 do you mean the 5th option in a select box? example: <select> <option>1</option> <option>2</option> <option>3</option> <option>4</option> <option>5</option> </select> Link to comment https://forums.phpfreaks.com/topic/59080-combo-box/#findComment-293377 Share on other sites More sharing options...
adam84 Posted July 9, 2007 Author Share Posted July 9, 2007 <select> <option VALUE=1>Hotmail</option> <option VALUE=2>Gmail</option> <option VALUE=3>Yahoo</option> </select> user enters 3 and i want to combo box to select Yahoo Link to comment https://forums.phpfreaks.com/topic/59080-combo-box/#findComment-293388 Share on other sites More sharing options...
RichardRotterdam Posted July 9, 2007 Share Posted July 9, 2007 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 More sharing options...
nogray Posted July 9, 2007 Share Posted July 9, 2007 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 More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.