I have two text boxes: A and B using Html.textboxfor
. TextBox 'A' is enabled and TextBox 'B' is disabled.
When I type values in Textbox 'A' and change focus away from the textbox, TextBox 'B' should be populated with some value.
For example: I am entering the value of TextBox A = "King"; if the focus is lost from the box, the value in the Textbox B should be "Peter", which should be filled automatically.
you can jsut give the textbox an attrbiute of onblur and call a method which will fill the second textbox
something like:
<script language="javascript">
function fllB()
{
var txtB = document.getElementById("txtB");
var txtA = document.getElementById("txtA");
if (txtA.value == "King")
{
txtB.value = "Peter";
}
}
</script>
<input type="text" id="txtA" onblur="fillB()" />
<input type="text" id="txtB" />
Below is the javascript function that I wrote to validate my input "Price" currency value.
<script language="javascript">
function validatePrice(textBoxId) {
var textVal = textBoxId.value;
var regex = /^(\$|)([1-9]\d{0,2}(\,\d{3})*|([1-9]\d*))(\.\d{2})?$/;
var passed = textVal.match(regex);
if (passed == null) {
alert("Enter price only. For example: 523.36 or $523.36");
textBoxId.Value = "";
}
}
If you want to fire the validation after you lost a focus from text box, then use “onblur” event which is as same as OnLostFocus() in most of the WinForm controls.
<asp:TextBox ID="TextBox19" runat="server" Visible="False" Width="183px"
onblur="javascript:return validatePrice(this);"></asp:TextBox>
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