tags:

views:

56

answers:

3

hi I have a two boxes, a 'parent' select box and a 'child' text box. how can i change values that are inside the 'child' text box to current date, depend on what is selected in the 'parent' select box.

+2  A: 
  1. Wire an onchange event for the select box.
  2. Retrieve the selected value
  3. Assign the selected value to the text box

If you can use jQuery (which I suggest)

<script>
    $(document).ready ( function () {
     $("#sel1").change ( function () {
      $("#txt1").val ( $(this).val() );
     });
    });
</script>
<select id="sel1">
    <option value="1">1</option>
    <option value="2">2</option>
    <option value="3">3</option>
    <option value="4">4</option>
</select>

<input type="text" id="txt1" />
rahul
A: 

I won't give you cde, just how to do it

The Select box has Text and Value properties for each Item, also the Select has a javascript Event that tells you when the SelectedIndex has changed
On that Event you should read the Value from the SelectedItem and write it to the TextBox

pixel3cs
I think the first answer is the code, and my answer is the explanation
pixel3cs
A: 

Here's some code, which has the multiple advantages of not requiring jQuery and working before the document finishes loading:

<form>
  <select name="sel1" onchange="this.form.elements['txt1'].value = this.options[this.selectedIndex].text;">
    <option value="1">1</option>
    <option value="2">2</option>
    <option value="3">3</option>
    <option value="4">4</option>
  </select>

  <input type="text" name="txt1">
</form>
Tim Down