Changing input before KeyCode == 13 was entered
Hi,
I am trying to re-assign a dom input element based on it's content after hitting the [enter] key.
thing is...the [enter] is executed ahead of the conditions. Confirm dialog works fine but I don't want to use any dialogs.
It's part of a chrome extension...
Here is my code:
document.onkeyup = returnKey;
function returnKey(evt)
{
var evt = (evt) ? evt : ((event) ? event : null);
var node = (evt.target) ? evt.target : ((evt.srcElement) ? evt.srcElement : null);
if ( node.value == 'fi' ) { node.value = "כן"; }
if ( node.value == 'kt' ) { node.value = "לא"; }
}
I want to change the value of node.value,
only after that, [enter] should be executed. ( with updated value ).
Thanks,
Asaph.
conditions should look like that ( just to show you the basic logic of what I want to achieve. )
if ( evt.keyCode == 13 )
{
if ( node.value == 'fi' ) { evt.srcElement.value = "כן"; }
if ( node.value == 'kt' ) { evt.srcElement.value = "לא"; }
}
but it's not working.
thanks
Pressing Enter in a text field causes form submission, so you must cancel submission by returning false if applicable.
The keyup event is too late to be of use:
Code:
<script type='text/javascript'>
document.onkeypress = returnKey;
function returnKey( e )
{
var evt = e || window.event,
node = evt.srcElement || evt.target,
query = false;
if ( evt.keyCode == '13' && ( query = /^(fi|kt)$/.test( node.value ) ) )
node.value = "??";
return !query;
}
</script>
Where used, return should be executed unconditionally and always as the last statement in the function.
That's my signature, it's not part of the damn post!
well, thanks but that's not it
What do you mean "that's not it"?
Are you saying I got the spec wrong or that you can't get it to work?
Where used, return should be executed unconditionally and always as the last statement in the function.
That's my signature, it's not part of the damn post!
The code is implemented, but it's not doing what it should.
Originally Posted by
assaf.vilmovski
The code is implemented, but it's not doing what it should.
That answers neither question.
Does this demo do what you expected?
Where used, return should be executed unconditionally and always as the last statement in the function.
That's my signature, it's not part of the damn post!
It does.
I`m gonna take another look at this later.
Thank you very much for your time.
It does.
It just didn't work on the extension.
I`m gonna take another look at this later.
Thank you very much for your time.
by the way, is there a more human reabable way of writing this?
You know, to simple things out
Originally Posted by
assaf.vilmovski
is there a more human reabable way of writing this?
You know, to simple things out
Simplifying it would make it more complicated, and I'm sure your teacher will understand it as it is.
Where used, return should be executed unconditionally and always as the last statement in the function.
That's my signature, it's not part of the damn post!
well now you're insulting me...
How can I insert my code before their's?
Any ides?
One thought is using innerHTML to rewrite the targeted website's source.
now I see the real problem...
the website that the extension is working on is already using an onkeydown on the input.
So it causes their code to be executed before mine...
In all other websites it's working great.
Thread Information
Users Browsing this Thread
There are currently 1 users browsing this thread. (0 members and 1 guests)
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
Forum Rules
Bookmarks