I found this handy little script on the net that means the user can only press backspace or numbers in form input.
<script type="text/javascript">
function numbersonly(e){
var unicode=e.charCode? e.charCode : e.keyCode
if (unicode!=8){ //if the key isn't the backspace key (which we should
allow)
if (unicode<48||unicode>57) //if not a number
return false //disable key press
}}
</script>
My paste catch trigger for autocomplete works fine for Ctrl-V. If using right click/paste, however, it will not trigger autocomplete. The paste event does fire with both keyboard and mouse, but for some reason it's not triggering the autocomplete, but again - Only with the mouse paste.
I am trying to fix a bug in WYSWYG (NicEdit). When I copy and paste from a site it pulls the styles and elements that are in that copy ~ all I want is just the plain text.
So I am starting a script that can be used to override the paste in the textarea and strip the copy to plain text.
This is what I have so far (it's just a start):
So, when I paste in a texarea right now there is an alert that says "paste". What I want is to get the data in the paste and then strip it to plain text - then paste it in the textarea.
NOTE: Please make this intact if you want to use this script. Thanks. *************************/
function PasteSplitter(origMaxlen){ //you can also pass as many field references as needed in the argument var me = this; var arglen = arguments.length; this.flds = new Array(); this.maxlen = origMaxlen; this.filter = this.NUMERIC; //default filter for (var i=1; i<arglen; i++){ this.flds[i-1] = arguments[i]; } if (this.flds.length > 0){ var fld1 = this.flds[0]; fld1.onkeydown = function(event){ extendMaxLength(me.flds, me.maxlen, event); } fld1.onkeyup = function(event){ splitPaste(me.flds, me.maxlen, event) } if (typeof fld1.onbeforepaste != "undefined"){ fld1.onbeforepaste = function(event){ extendMaxLength(me.flds, me.maxlen, event); } } if (typeof fld1.onpaste != "undefined"){ fld1.onpaste = function(event){ //we need a little delay here before calling the function setTimeout(function(){ splitPaste(me.flds, me.maxlen, event); }, 10); } } }
function extendMaxLength(arrFlds, maxlen1, evt){ if (!evt) evt = event; if (evt.ctrlKey || evt.type=="beforepaste"){ var len = maxlen1; var arrlen = arrFlds.length; for (var i=1; i<arrlen; i++){ len += arrFlds[i].maxLength; } arrFlds[0].maxLength = len + arrlen - 1; //allow separators in beetween sets (e.g. - . /) } }
function splitPaste(arrFlds, maxlen1, evt){ var s = arrFlds[0].value; //apply filter switch (me.filter){ case me.NUMERIC: s = s.replace(/D/g, ""); break; case me.ALPHANUMERIC: s = s.replace(/W/g, ""); break; case me.ALPHA: s = s.replace(/[^a-zA-Z]/g, ""); break; default: //custom filter s = s.replace(me.filter, ""); } var len = s.length; if (len <= maxlen1){ arrFlds[0].value = s; if (arrFlds.length > 1 && len==maxlen1){ arrFlds[1].focus(); } return; } else { var len=0, start=0, arrlen=arrFlds.length, el; for (var i=0; i<arrlen; i++){ el = arrFlds[i]; len = (i>0) ? el.maxLength:maxlen1; el.value = s.substr(start, len); if (el.value=="" || el.value.length < len){ el.focus(); el.value = el.value; //this trick puts cursor at the end of value after focusing on the field first return; } start += len; } } arrFlds[0].maxLength = maxlen1; //change back to original maxlength } }
PasteSplitter.prototype.setFilter = function(filter){ //custom filter (regexp) may be specified this.filter = filter; } /***************end of script******************/
//SAMPLE USAGE function init(){ var f = document.forms[0];
//serial number var ser = new PasteSplitter(f.ser1.maxLength, f.ser1, f.ser2, f.ser3); //pass the original maxlength of the first field and all the references of as many fields as needed ser.setFilter(ser.ALPHANUMERIC); //set filter to alpha-numeric
//sss number var sss = new PasteSplitter(f.sss1.maxLength, f.sss1, f.sss2, f.sss3, f.sss4); //default filter (numeric) will be used } window.onload = init; //END OF SAMPLE USAGE
</script> </head> <body> <form> <h1>Paste Splitter v1.0</h1> <p>Copy any alpha, numeric or alphanumeric characters, even including separators such as slash (/), hyphen (-), dot (.) or anything, and then paste it in the first field. The characters will be split to all the fields automatically excluding the separator. Very useful for fields like serial number, Social Security number, telephone number and the like. The script works on the basis of the <code>maxlength</code> attribute of the field. It degrades well for JavaScript-disabled browsers, making the <code>maxlength</code> attribute untouched. It works well for IE for all paste commands (<code>CTRL+V</code>, <code>Edit->Paste</code>, <code>right-click->Paste</code>) and partially works for Firefox (<code>CTRL+V</code> only).</p> <fieldset> <legend>Information</legend> <label for="ser1">Serial No.</label> <input type="text" maxlength="5" size="5" id="ser1" name="ser1" /> - <input type="text" maxlength="4" size="4" id="ser2" name="ser2" /> - <input type="text" maxlength="6" size="6" id="ser3" name="ser3" /><br /> <label for="sss1">SSS No.</label> <input type="text" maxlength="2" size="2" id="sss1" name="sss1" /> - <input type="text" maxlength="7" size="7" id="sss2" name="sss2" /> - <input type="text" maxlength="2" size="2" id="sss3" name="sss3" /> - <input type="text" maxlength="1" size="1" id="sss4" name="sss4" /> </fieldset> </form> </body> </html>
If you have any comments, suggestion, bugs found, please feel free to post them here.
Is it possible to do this: when clicking a button, info is selected and copied to computers "cache" (don't know exact name) ready for pasting in other application like Word?
I have a web app (front end jquery, backend django) that allows usersto type commens into a text area. My users are asking for the abilityto cut and paste images into their comments. They want to use anwindows app called mwsnap to basically snap images from their desktop,then ctrl-v to copy the image into my django app. Does anyone knowwhat sort of client side support is needed to do this? I am fairlyadept at jquery/javascript, but haven't seen anything like this thoughit does seem like a very reasonable request since they are certainlyable to cut and paste into Outlook this way. However, when I try tocut and paste this way into yahoo mail or gmail it doesn't work, soperhaps this is a hard thing to do in a web app.
This may or may not be possible, but if anyone knows a way to do it,I'd love to hear from you.Basically, I simply (?) want to copy an image (e.g. from ALT-PrintScreen or 'Copy Image'), and paste/drop it into an img tag on a pageso it appears on the page. I can then resize, drag-drop, etc. asrequired.I've had a rummage around the net, but can't find anything. Maybe it's
How to make a form that automatic tab when we paste something into the box and sort it out automatically. Like cd-key box. When we copy n paste cd-key into the box it automatic inert everything into correct places.
I have built my menu as I needed on a seperate asp page and it works beautifilly. Then moved it to my actual web page and it ceases to function. and I am getting an error 'document.doublecombo.SECTOR is Null or object does not exist' I will include the non working piece in the following post, too long for here. Code:
I was just doing a simple stuff of executing system copy, delete etc. commands using execCommand method of js.
I have made two textareas, in one i am inputting some text and by hitting on the buttons i am executing copy, cut etc. commands.
Problems::::----
In this the paste button is not working. Like i am copying some text from one textarea, it is not pasting into other textarea.
Also I want to do select all for the textareas only. Like if cursor is on textarea1 and if I am hitting on selectAll button it should only select the textarea1 content. Currently it is selecting the whole page content. code...
In the following j and k are already initialized to zero and my match statements don't even find trkpt, much less the floating point values on that line.
Code: lines = document.gpxform.InputField.value.split(" "); for (i = 0; i < lines.length; i++) {
I am trying to copy a form that is in one frame, using a button on another frame. The form has a couple of tables inside it. I can get it working when the button is in the same frame, but not in different ones. I get an "invalid argument" error on the controlRange.addElement(x) line.
What I have so far is:
<script language='javascript'> function CopyForm() { if (document.body.createControlRange) { var x = window.parent.fraRight.document.getElementById('Fo rm1'); x.contentEditable = 'true' var controlRange; controlRange = document.body.createControlRange(); controlRange.addElement(x); controlRange.execCommand("Copy"); x.contentEditable = 'false' alert('The table is now copied to memory. Start Excel, and Paste the table into a new worksheet.'); } </Script>
where fraRight is the name of the frame the form is in, and Form1 is the name of the form I want to copy. The only thing I have changed from when it was working in the one frame, is:
var x = window.parent.fraRight.document.getElementById('Fo rm1'); used to be var x = document.getElementById('Form1');
I can do things like alert(x.name) and get the right name of the form, so I think I have got the object properly. Is there any other way to make sure?
I have implemented alpha & alphanumeric plugin in my code.I am doing this validation in few text boxes.my problem is, the text box don't allow copy paste in FireFox.. but its is allowing in IE.. What might be the problem with firefox..?
I created a simple WYSIWYG for creating CSS based webpages. It works exactly as assumed in Safari and Chrome. However, in firefox, when you copy/paste more than one line of text, instead of formatting it as html, in puts in line breaks causing the array storing all of the data to break into multiple lines and causing an unterminated string literal.
1. suggest why it is behaving this way? 2. suggest a work around to allow it to work on FF?
i have two text boxes in Web application. When i enter data in first textbox second will enable automatically. i have written javascrit of onblur and onchanges and onkeyup event to enable the second textbox, it works fine but the problem is when i copied and pate it in first textbox throw the mouse event the second testbox is not enabled.
I have busy forum site where some of the spammers copy/paste the forum topics from other sites! I would like to disable copy/paste using Javascript! Its possible? How to do it!
I want to give the user possibility to paste an image into a webform. I don't need to display the image, all I need is the image's location.I know it's possible because the guys at CKEditor(and other editors) are doing it. If you go here, [URL] and paste an image you copied and then right click on it and go to image properties you'll see they have the image's address. How can this be done?
I got a pre-formatted spreadsheet. would it be possible using js to copy the data from a table on the current webpage, open the spreadsheet and paste the content ? if so, anyone got any links or pointers?
i've already tried google - but all i get is ActiveX methods which work in a very few cases.
I want add an onclick link from an iFrame to a form field on the parent. After to ba placed on the form field, clicking on the link a new page will be open on the iframe. I am trying this: