How can I populate a message box when mouse cursor enters in a text box?
I am using 3 text boxes. When I click on 2nd text box I want to show 1st text box value in message box (if 1st text box passed the validations). Same开发者_运维知识库 procedure when i click on 3rd textbox I want to show 1st text box value and 2nd text box value in message box(if 1st text box,2nd text box passed the validations).
Regards, NSJ
Use the onmouseover
event on the text boxes if you want the function to fire when mousing over.
Use the onfocus
event on the text boxes if you want the function to fire when the cursor moves into the control.
Textbox 2 (mouse over):
onmouseover="alert(textbox1.value);"
Textbox 3 (focus):
onfocus="alert(textbox1.value + ' ' + textbox2.value);"
If you are using a javascript library like jQuery, it is best to attach to the events through it to maintain separation of concerns.
Try this one:
ASPX:
<asp:TextBox ID="txtFirst" runat="server" Text="First"></asp:TextBox>
<asp:TextBox ID="txtSecond" runat="server" Text="Second"></asp:TextBox><br />
<asp:TextBox ID="txtThird" runat="server" Text="Third"></asp:TextBox><br />
JAVASCRIPT:
$(document).ready(function(){
$("#txtSecond").focus(function(){
alert($("#txtFirst").val());
});
$("#txtThird").focus(function(){
alert($("#txtFirst").val());
alert($("#txtSecond").val());
});
});
精彩评论