Option Auto Select

[Total: 0    Average: 0/5]

Automatically selects an item from the drop-down option box (SELECT TAG) without writing VBScript in each option tag to display SELECTED once matched.

Head Code:

<SCRIPT language=JavaScript>
function Show() {
  var success = -1;
  for (var i=0; i < document.frmInput.cboNames.length; i++) {
    if (document.frmInput.cboNames.options[i].text == document.frmInput.txtInput.value)
      success = [i];

Body Code:

This example allows a user to enter the exact item in the select list and then click on "show" button.
Then the item in the select list will be automatically selected for the user.
<FORM name="frmInput">
<TABLE border=1 cellspacing=1 cellpadding=1>
<TD><input type=text name="txtInput" value=""></TD>
<TD><input type=button name="btnInput" value="Show" onclick="Show();"></TD>

<TD>Auto: <SELECT size=1 name="cboNames">
<option value="1">Idris
<option value="2">Dave
<option value="3">Fred
<option value="4">Bob

Times Viewed: 2

Leave a Reply

Your email address will not be published. Required fields are marked *