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.
views:
56answers:
3
+2
A:
- Wire an onchange event for the select box.
- Retrieve the selected value
- 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
2009-10-07 11:20:51
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
2009-10-07 11:23:04
I think the first answer is the code, and my answer is the explanation
pixel3cs
2009-10-07 11:23:55
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
2009-10-07 12:04:25