Ok so I have a StartDate field:
<asp:TextBox ID="txtnewStartDate" runat="server" Text='<%# Bind("StartDate", "{0:MM/dd/yyyy}")%>'
CssClass="datepicker grid_5 text"></asp:TextBox>
I also have a TextBox which I would like to be auto filled based on the StartDate.
<asp:TextBox ID="txtDateBatch" Text='<%# Bind("DateBatch") %>' runat="server" CssClass="text"></asp:TextBox>
So for example the StartDate field will look like: 9/1/2015 (After a user has selected a date from the date box)
Now based on the date someone selected in this field the DateBatch field will look like: Batch-912015
I have seen an example using javascript but im not sure how to call the variables from javascript to asp or c#.
Javascript Ex:
<script type="text/javascript">
function autoBatch() {
value1 = $('#StartDate').val();
var batch = "Batch-" + value1;
}
</script>
Please let me know if I was not informative enough or anyone needs more info thanks! I don't need to use javascript whatever method works I would just like to understand how to do this from start to finish mainly confused on how to complete this fully.
Try adding an OnTextChanged event to the textbox, as below....
<asp:TextBox ID="txtnewStartDate" runat="server" OnTextChanged="txtnewStartDate_TextChanged" Text='<%# Bind("StartDate", "{0:MM/dd/yyyy}")%>' CssClass="datepicker grid_5 text"></asp:TextBox>
Then in your code behind, catch the value and update your DateBatch, as below....
protected void txtnewStartDate_TextChanged(object sender,EventArgs e)
{
txtDateBatch.Text = txtnewStartDate.Text
}
Or with your batch code added.....
protected void txtnewStartDate_TextChanged(object sender,EventArgs e)
{
txtDateBatch.Text = "Batch-" & txtnewStartDate.Text.replace('/','')
}
Something like that.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With