Reputation: 605
Good morning, as the title suggests, how to run function (JavaScript) when changing the value of a field (no from empty in compiled)?
Upvotes: 0
Views: 120
Reputation: 148110
If you want to check on each key press then
With javascript
<input type="text" id="textbox" onkeyup="TextBoxChanged()" />
function TextBoxChanged(){
alert("changed");
}
With jquery
This requires you to import jquery file to be imported in the web page.
$(document).ready(function(){
$('#textbox').keyup(function() {
alert("changed");
});
});
Bind change event with textbox, this will cause event when textbox loses focus.
<input type="text" id="textbox" />
$(document).ready(function(){
$('#textbox').change(function(){
alert("changed");
});
});
Upvotes: 1
Reputation: 28763
You can also add better that
$('document').ready(function(){
$('select_id').live('change',function(){
//Do your code
});
})
it will be better and suggestable also
Upvotes: 2
Reputation: 2828
You first define an id or class for the input field like that
<input type="text" id="myId" />
then you bind a function to his change event like this
function myFunction(){
// Your function here !
}
$('#myId').change(function(){
// Your function call here
myFunction();
});
Upvotes: 0
Reputation: 28763
Try like this
$('document').ready(function(){
$('#select_id').change(function(){
//Do your code here
});
})
Upvotes: 4