Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New to the CF scene
    Join Date
    Nov 2012
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    On change event not fired with dynamically loaded data

    I am dynamically loading data in the input type text and triggering alert if the value of the text box is changed. But my code does not seem to work. Please provide suggestions.
    Code:
    <!DOCTYPE html>
    <html>
    <head>
    <script src="//ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js">
    </script>
    <script>
    $(document).ready(function(){
    $("input").val("value");
    });
    function valueChanged()
    {
    alert("value changed");
    }
    </script>
    </head>
    <body>
    
    <input type="text" onchange="valueChanged()">
    <p>Write something in the input field, and then press enter or click outside the field.</p>
    
    </body>
    </html>
    Last edited by VIPStephan; 01-21-2013 at 10:49 AM. Reason: corrected code BB tags

  • #2
    New Coder
    Join Date
    Jan 2013
    Posts
    10
    Thanks
    3
    Thanked 1 Time in 1 Post
    Since you're using JQuery, why not:

    PHP Code:
            <script>
                $(
    document).ready(function(){
                    
                    $(
    "input").val("value");

                    $(
    "input").change(function() {
                        
    alert("changed");
                    });
                });
                
            
    </script>
        </head>
        <body>
            <input type="text" id="text1"/>
        </body> 
    Working example: http://jsfiddle.net/96gXw/


  •  

    Tags for this Thread

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •