CodingForums.com

CodingForums.com (http://www.codingforums.com/index.php)
-   JavaScript frameworks (http://www.codingforums.com/forumdisplay.php?f=62)
-   -   On change event not fired with dynamically loaded data (http://www.codingforums.com/showthread.php?t=286179)

varalakshmi 01-21-2013 08:55 AM

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>


Kyle123 01-21-2013 11:06 AM

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/


All times are GMT +1. The time now is 02:28 PM.

Powered by vBulletin®
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.