Value entered in text box appears automatically in combo box (or text box)

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • jessy
    New Member
    • Oct 2006
    • 106

    #1

    Value entered in text box appears automatically in combo box (or text box)

    i'm new to ajax and i have a simple text box and a combo box and i need whenever the user enters a text in the text box that value appears at the combo box or whatever field( another text box maybe )
  • RamananKalirajan
    Contributor
    • Mar 2008
    • 608

    #2
    Do u really want to do this thing with AJAX, u can achieve this task wothout AJAX.

    [HTML] <html>
    <head>
    <script type="text/javascript">
    function doThis()
    {

    var x = document.getEle mentById('myTex t').value;
    if(x==""||x==nu ll||x==false)
    {
    alert("Please Enter the Value in the Text Field");
    document.getEle mentById('myTex t').focus;
    }
    else
    {
    document.getEle mentById('mySel ect').add(new Option(x,x));
    }
    }
    </script>
    </head>
    <body>
    Enter Text: <input type="text" id="myText" name="myText">
    &nbsp;&nbsp;&nb sp;
    <input type="button" value="Add to Combo" onclick="doThis ()">
    <br/><br/>
    <select id="mySelect" name="mySelect" >
    <option>Selec t</select>
    </select>
    </body>
    </html>[/HTML]

    If u want to do it with Ajax, post the code what u have tried. I will try to help u out

    Regards
    Ramanan Kalirajan

    Comment

    • acoder
      Recognized Expert MVP
      • Nov 2006
      • 16032

      #3
      jessy, I have changed your thread title.

      Please remember to provide a meaningful Title for any threads started (see the FAQ entry Use a Good Thread Title).

      This helps to ensure that other members, and also the general public, will have a better chance of finding answers to any similar questions.

      Moderator.

      Comment

      • jessy
        New Member
        • Oct 2006
        • 106

        #4
        Thanks alot for you reply .. did what u said although i was trying to try something new (like ajax) but anyway, now i need when this value is added to the combo box the old option which is ( no data added ) be removed from the combo box
        here's my trial :

        Code:
        var opt= document.getElementById("no");
                 opt.remove(0);
        where "no" is the name of the option i want to remove not the name of the select statement

        Comment

        • RamananKalirajan
          Contributor
          • Mar 2008
          • 608

          #5
          Originally posted by jessy
          Thanks alot for you reply .. did what u said although i was trying to try something new (like ajax) but anyway, now i need when this value is added to the combo box the old option which is ( no data added ) be removed from the combo box
          here's my trial :

          Code:
          var opt= document.getElementById("no");
                   opt.remove(0);
          where "no" is the name of the option i want to remove not the name of the select statement

          Removing u can do easily

          [HTML] var sel = document.getEle mentById('mySel ect').selectedI ndex;
          document.getEle mentById('mySel ect').remove(se l);[/HTML]

          This piece of code will do the work what u are aiming at.

          Regards
          Ramanan Kalirajan

          Comment

          Working...