View Single Post
Old 11-26-2012, 05:07 AM   PM User | #2
DanInMa
Senior Coder

 
DanInMa's Avatar
 
Join Date: Nov 2010
Location: Salem,Ma
Posts: 1,307
Thanks: 12
Thanked 204 Times in 204 Posts
DanInMa is on a distinguished road
here is a really simple example. it assumes your textarea has an id of "textareaid" and your auto fill button has an id of "autofillid"
- side note you should really have a valid form element. having valid html can only help you.


Code:
function getuserdata(){
var $ta= $("#textareaid");
var $data= $ta.val().split('\n');
var $first = $data[0].replace('First Name');
var $last = $data[1].replace('Last Name');
var $post = $data[2].replace('Postcode');
$('#f1').val($.trim($first));
$('#f2').val($.trim($last));
$('#f3').val($.trim($post));
}

});
$("#autofillID").click(function(){
getuserdata();
});
Also, if you wanted to, you can do away with the autofill button and jsut fill the fields automatically upon the paste event like so:


Code:
$("#textareaid").bind('paste',function(){
getuserdata();
});
__________________
- Firebug is a web developers best friend! - Learn it, Love it, use it!
- Validate your code! - JQ/JS troubleshooting
- Using jQuery with Other Libraries - Jslint for Jquery/other JS library users

Last edited by DanInMa; 11-26-2012 at 05:25 AM..
DanInMa is offline   Reply With Quote