简体   繁体   中英

Get Text value after past value in text box

I want to get text value when paste value in text box by using jQuery. Like i have paste value 123456 in text box then after paste i want get that value.

I was using .change but it give value after outfocus from text box. Keypress not working when past value.

Is anyone give me solution for this.or give me trick for achieve this.

Actually i am scanning barcode from barcode device after scan barcode value added on text-box. after scan i want to submit form that's why i am finding event that will fire after scan.

Thanks

Use a small timeout to get the pasted value.

 document.getElementById('getval').onpaste =function() { setTimeout(() => { let value = document.getElementById('getval').value; console.log(value); },200); } 
 <input type="text" id="getval"> 

You can use "bind" function and "paste" event.

 $(".getval").bind("paste", function(e){ var pastedData = e.originalEvent.clipboardData.getData('text'); alert(pastedData); } ); 
 <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <input type="text" class="getval"> 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM