How to fire Javascript event when user drags text into textfield? -
i have form formats text inputed several textfields, , make possible user type text, paste text, , drop text textfield. javascript event format().
i have used onkeyup="format() when user types text , pastes text, can't figure out event allow user select text, drag , drop on textfield, , fire event automatically update formatted text. have tried ondrop, onmouseup, , onchange no avail.
i have feeling onmouseup property working, problem event fires right after mouse released, before text textfield has new user text, looks if didn't fire, when indeed did, there nothing in textfield. be? if so, use settimeout delay event 500 milliseconds (or something) until text there?
here javscript:
<script language="javascript"> function format() { var author = document.form.author.value; var credentials = document.form.credentials.value; var date = document.form.date.value; var publication = document.form.publication.value; var title = document.form.title.value; var evidence = document.form.evidence.value; var tagline = document.form.tagline.value; document.getelementbyid('txtarea').innerhtml = ("<b>" + tagline + "</b>" + "</br >" + "<br />" + "<i>" + "<u>" + author + " " + date + "." + "</u> " + author + " (" + credentials + ") " + date + " " + publication + " " + title + " " + (window.top.getbrowser().selectedbrowser.contentwindow.location.href) + "</i>" + "<br />" + "<br />" + evidence);} function clearform() { document.getelementbyid('txtarea').innerhtml = ""; } </script> here 1 of 7 textfields have (i have onkeyup covers type , paste, don't know use drag , drop):
<form class="right_aligned" name="form" method="get" action="" id="form" onkeyup="format()" onmouseup="format()" ondrop="format()"> <div style="float: left;"><input ondblclick="this.value=''" type="text" name="publication" value="publication..." id="publication" style="border:1px solid;border-color:#b0b0b0;width:225px;padding:4px;margin:10px;color: #000;" ondrop="format()" ondragover="{this.value=''; this.style.color='#000';}" onfocus="if (this.value==this.defaultvalue) {this.value=''; this.style.color='#000';}" onblur="if(this.value=='') {this.value=this.defaultvalue; this.style.color='#000';}"></div> ...and here contenteditable div text outputted to:
<div contenteditable id="txtarea" ondblclick="document.execcommand('selectall',false,null);" style="float:left;overflow:auto;padding:5px;background-color:#fff;border:1px solid;border-color:#b0b0b0;outline:none;width:213px;height:260px;font-size:.75em;margin-left:10px;margin-right:10px;margin-bottom:10px;margin-top:5px" type="text"></div> by way, firefox extension, cross browser not issue. has work in firefox.
there may way out there, can use settimeout 1 millisecond time , seems work fine:
<p>duis nunc nisl, luctus nec auctor id, iaculis eu nibh. nunc odio velit, pretium et scelerisque eget, auctor eget erat. cras id nulla nec odio vestibulum egestas ac in mi. vivamus mollis suscipit condimentum. sed laoreet eros ut lorem tempor porttitor. etiam eget erat @ lacus facilisis aliquam eget id purus.</p> <br/> <textarea ondrop="formatondrop(this)" onchange="formatonchange(this)" id="textarea"></textarea> <br/> <input type="text" id="inputtext" ondrop="formatondrop(this)" onchange="formatonchange(this)"/> function formatondrop(el){ formatelement = el; //alert('ondrop: ' + el.id + ' changed ' + el.value); settimeout(function(){format()},1); } function formatonchange(el){ formatelement = el; //alert('onchange: ' + el.id + ' changed ' + el.value); settimeout(function(){format()},1); } function format() { alert('format: ' + formatelement.id + ' changed ' + formatelement.value); } note, formatonchange() function never called when selecting , dropping text, fire onblur when copying , pasting.
Comments
Post a Comment