Reputation:
I want it so that when a person presses the enter button, it would execute my function.
Here is the code:
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js">
$('textmoney').keydown(function (e){
if(e.keyCode == 13){
moneyFunction();
}
})
</script>
Why won't this work?
Upvotes: 0
Views: 40
Reputation: 33870
As others stated, you are missing a ID or class selector before textmoney
. It should be #textmoney
or .textmoney
.
But you are also inserting your script inside the script tag loading jQuery. You can't do that. It is either you load a source or you run the code between the tag. The src
is always prioritized so your code will never be run.
Separate the two, use 2 script tags :
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script>
<script>
$('#textmoney').keydown(function (e){
if(e.keyCode == 13){
moneyFunction();
}
});
</script>
Upvotes: 0
Reputation: 9808
I think you are missing either id or class in jQuery selector,
so it should be like $('#textmoney')
or $('.textmoney')
depending on your selector.
Upvotes: 0
Reputation: 82231
You are missing either ID or class selector while attaching the event.
If textmoney
is class
$('.textmoney').keydown(function (e){
if(e.keyCode == 13){
moneyFunction();
}});
If textmoney
is ID
$('#textmoney').keydown(function (e){
if(e.keyCode == 13){
moneyFunction();
}});
Upvotes: 3