Sunday 15 March 2015

html - How to pass the text pasted in a textbox to javascript function using onPaste event? -



html - How to pass the text pasted in a textbox to javascript function using onPaste event? -

i have html page this:

<html> <body> <input type="text" onpaste="return myfunction()"></input> </body> </html>

i have javascript this:

function myfunction(){ var text = ; if(text == "abc"){ alert("accepted"); homecoming true; } else{ alert("rejected"); homecoming false; } }

i want assign pasted string var text

this question may seem duplicate. but, want acheive without jquery.

this possible solution: http://jsfiddle.net/lqdfa9co/

i added this:

onpaste="var e=this; settimeout(function(){myfunction(e)}, 4);"

and function changed this:

function myfunction(e){ var text = e.value; if(text === "abc"){ alert("accepted"); } else{ alert("rejected"); } }

it necessary utilize settimeout on onpaste event in order value within function. caused fact event triggered before value assigned

edit: in order reply changed question, updated "rejected phase" emptying input value http://jsfiddle.net/lqdfa9co/1/

javascript html input paste

No comments:

Post a Comment