set the value of select elements, but selecting the appropriate options. : Form TextBox « jQuery « JavaScript DHTML






set the value of select elements, but selecting the appropriate options.

 




<html>
  <head>
    <script type="text/javascript" src="js/jquery-1.3.2.js"></script>
    <script type="text/javascript">
        $(document).ready(function(){

            $("button").click(function () {
              var text = $(this).text();
              $("input").val(text);
            });
        });
    </script>
    <style>
      .selected { color:red; }
      .highlight { background:yellow; }
    </style>    
  </head>
  <body>
    <body>
      <div>
        <button>A</button>
        <button>B</button>
        <button>C</button>
      </div>
      <input type="text" value="click a button" />
    </body>
</html>

   
  








Related examples in the same category

1.Change text field CSS
2.Set textbox value
3.Text box selected event
4.Text input change event
5.Find the value of an input box.
6.To add a validity test to all text input elements:
7.Focus event fires when an element receives focus either via the pointing device or by tab navigation.