Reputation: 39501
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.
Upvotes: 0
Views: 341
Reputation: 324567
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>
Upvotes: 0
Reputation: 187040
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" />
Upvotes: 2
Reputation: 2288
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
Upvotes: 0