You must Sign In to post a response.
  • Category: .NET

    javascript to set selected value of dropdown list box

    The forum thread has not been reviewed by Editors yet. Readers are advised to use their best judgement before accessing this thread.
    This thread will be reviewed shortly.
    If you think this thread contain inappropriate content, please report to webmaster.
    i have a dropdown list box it contain " A,B,C,D,E". And i have a textbox .

    if i give " B " in text box ,the listbox value of " B " should become a selected value

    pls if any body knew tel me

    by durai
  • #46592
    Type Only Capital letters in a text box

    Its Only forHTML Controls


    <form id="frm">
    <input type="text" id="txt" name="txt" onkeyup="frmchng(this.value)">
    <select id="slt"><option value=A>A</option>
    <option value=B>B</option>
    <option value=C>C</option>
    <option value=D>D</option>
    <option value=E>E</option>

    </select>
    </form>

    <script language="javascript">
    function frmchng(val)
    {

    for(i=0;i<document.all('slt').length;i++)
    {


    if(document.all('slt').options[i].value==val)
    {
    document.all('slt').selectedIndex=i

    }


    }


    }
    </script>

  • #46596
    <script language="javascript">
    function fnSetDDL()
    {
    for(var i=0;i<=document.getElementById("DropDownList1").length-1;i=i+1)
    {
    var ddlText=document.getElementById("DropDownList1").options[i].outerText;
    txtText=document.getElementById("TextBox2").value;
    if(ddlText==txtText)
    {
    document.getElementById("DropDownList1").selectedIndex=i;
    break;
    }
    }
    }

    </script>



    private void Page_Load(object sender, System.EventArgs e)
    {
    if(IsPostBack==false)
    {
    TextBox2.Attributes.Add("onkeyup","fnSetDDL();");
    // bindDropDown();
    }
    }

  • #46597
    1.copy and paste the following in html page head section

    <script language="javascript">

    function setFocus()
    {

    var a=document.getElementById('TextBox1').value;
    alert(a.toUpperCase());
    for (i=0;i<document.getElementById('DropDownList1').length;i++)
    {

    if (a == document.getElementById('DropDownList1').options(i).text)
    {
    document.getElementById('DropDownList1').options(i).selected = true;
    return;
    }
    }

    }
    </script>
    2. in page_load()
    TextBox1.Attributes("onblur") = "setFocus();"
    3. execute


This thread is locked for new responses. Please post your comments and questions as a separate thread.
If required, refer to the URL of this page in your new post.