-1

I want textbox to automatic call jQuery when the text/value changed. At the start, the readonly owner textbox is empty. I only can select the name and then it will automatic paste the name to tbAdd_Powner textbox. After it pasted, I want it to automatic call it jQuery to get value from tbAdd_Powner textbox and pass it to txtPass textbox. For example, I select Joe then it will paste Joe in tbAdd_Powner textbox then it call jQuery to pass Joe to txtPass textbox.

I tried the codes below and it doesn't work.

Here is jQuery and html example,

<%@ Page Title="" Language="C#" MasterPageFile="~/Site.master" AutoEventWireup="true" CodeFile="testtest.aspx.cs" 
Inherits="testtest" EnableEventValidation="false" Async="true" MaintainScrollPositionOnPostback="true" %>



    <script language="javascript" type="text/javascript">
     $(function () {

    $('#tbAdd_Powner').on('input',function () {
    alert("It Changed!");
    $('#txtPass').val($('#tbAdd_Powner').val());
 });

});        </script>
    <asp:TextBox ID="tbAdd_Powner" runat="server" ClientIDMode="Static" Enabled="false"></asp:TextBox>

    <asp:TextBox ID="txtPass" runat="server" Width="163px"></asp:TextBox>
StudentIT
  • 481
  • 2
  • 19
  • 45

2 Answers2

0

Because the ID is not the same as what you have thanks to .NET renaming them.

You need to do the same thing you do inside with <%=tbAdd_Powner.ClientID%>'

AKA:

$('#<%=tbAdd_Powner.ClientID%>').on(...

Other options would be use a class, partial selector, or Static option in the .NET code.

epascarello
  • 204,599
  • 20
  • 195
  • 236
0

This sounds for me like you need input. Also, don't mix jQuery with pure JavaScript:

$(function () {
  $('#tbAdd_Powner').on('input', function () {
       $('#<%=txtPass.ClientID%>').val($('#<%=tbAdd_Powner.ClientID%>').val());
  });
});

I don't know what values have ClientID, but you may need # selector to select the element by id.

See which is the difference between input and change.

Community
  • 1
  • 1
Ionică Bizău
  • 109,027
  • 88
  • 289
  • 474
  • I tried this example, it never fire at all because I added alert in tbadd_Powner function and it never alert. I use `$('#tbAdd_Powner').on('input',function () { alert("It Changed!"); $('#txtPass').val($('#tbAdd_Powner').val();` – StudentIT Jan 06 '14 at 20:41
  • @StudentIT What value `txtPass.ClientID` has? Do you have any errors in the page? Maybe the element doesn't exist. – Ionică Bizău Jan 07 '14 at 04:42
  • The value for `txtPass` is empty. There is not error in the page. – StudentIT Jan 07 '14 at 15:34
  • @StudentIT Not the input value but the `txtPass.ClientID`'s value. I am not familiar with ASP .NET but I guess you need to see what `id` the input has (use browser web inspector to see it). – Ionică Bizău Jan 07 '14 at 16:12