JavaScript - Prevent User Using Ctrl V To Paste
I wish for my users to retype their email address instead of the copy and paste method to ensure they have typed it correctly both times.
How could this be done, would it be Javascript ? Similar TutorialsThe code I will am including is far from finished, but some of what I do have works (the "submit" code does not work yet). I am able to prevent certain kinds of input including Shift-Ins pasting, but Ctrl-v pasting still works (and I do not want it to). Could you please tell/show me what code needs to be entered to my existing functions, or what new function I need to create (and call from my existing functions) to eliminate any kind of CtrlKey input? Thanks in advance, mitchellA <code> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <html> <head> <title> Mitchell's Test Form </title> <meta name="Generator" content="Alleycode HTML Editor"> <meta name="Description" content="Your description here..."> <meta name="Keywords" content="Your keywords here..."> <script type="text/javascript"> function is_it_A (e) {// allows only a-z, A-Z, <backspace>, <space>, apostrophe, and hyphen var a; document.all ? a = e.keycode : a = e.which; return ((a > 64 && a < 91) || (a > 96 && a < 123) || a == 8 || a == 32 || a == 39 || a == 45); } function is_it_P (w) {// allows only a-z, A-Z, 0-9, <backspace>, hyphen, and underscore var p; document.all ? p = w.keycode : p = w.which; return ((p > 47 && p < 58) || (p > 64 && p < 91) || (p > 96 && p < 123) || p == 8 || p == 45 || p == 95); } function is_it_N (i) {// allows only 0-9, <backspace> var n; document.all ? n = i.keycode : n = i.which; return ((n > 47 && n < 58) || n == 8); } function is_it_T (p) {// allows only 0-9, <backspace>, <right & left brackets()>, and hyphen var t; document.all ? t = p.keycode : t = p.which; return ((t > 47 && t < 58) || t == 8 || t == 40 || t == 41 || t == 45); } function is_it_E (m) {// allows only 0-9, a-z, A-Z, <backspace>, hyphen, <period (.)>, <at (@) sign>, and underscore var e; document.all ? e = m.keycode : e = m.which; return ((e > 47 && e < 58) || (e > 64 && a < 91) || (e > 96 && a < 123) || e == 8 || e == 45 || e == 46 || e == 64 || e == 95); } function xA (str) { return str.replace (/[^a-z\'\-\ ]/gi,""); } function xN (str) { return str.replace (/[^0-9]/gi,""); } function xT (str) { return str.replace (/[^0-9\(\)\ ]/gi,""); } function xE (str) { return str.replace (/[^a-z\0-9\-\_\.\@\_]/gi,""); } function validateFormOnSubmit (theForm) { var f=document.forms["theForm"]["fname"].value var l=document.forms["theForm"]["lname"].value var p=document.forms["theForm"]["pwd"].value var e=document.forms["theForm"]["eml"].value if (f==null || f=="") { fld.style.background = "red"; alert = ("Please enter your First Name."); return false; } else if (l==null || l=="") { fld.style.background = "red"; alert = ("Please enter your Last Name."); return false; } else if (p==null || p=="") { fld.style.background = "red"; alert = ("Please enter your Password."); return false; } else if (e==null || e=="") { fld.style.background = "red"; alert = ("Please enter your e-mail address."); return false; } else { fld.style.background = "white"; } } </script> </head> <body> <CENTER> <FORM name="theForm" onsubmit="return validateFormOnSubmit ()"> <H1>Please supply the following data...</H1> <br /> <FONT size="5"> <label for="fname">First Name: </label><INPUT type="text" onkeypress="return is_it_A(event)" onblur="this.value=xA(this.value)" name="firstname" id="fname"><br /> <br /> <label for="lname">Last Name: </label><INPUT type="text" onkeypress="return is_it_A(event)" onblur="this.value=xA(this.value)" name="lastname" id="lname"><br /> <br /> <label for="pwd">Password: </label><INPUT type="text" onkeypress="return is_it_P-(event)" onblur="this.value=xA(this.value)" name="password" id="pwd"><br /> <br /> <label for="eml">E-mail Address: </label><INPUT type="text" onkeypress="return is_it_E(event)" onblur="this.value=xA(this.value)" name="email" id="eml"><br /> <br /> <input name="info" type="submit" value="Done>>"> </font> </CENTER> </FORM> </body> </html> </code> Hello, I am trying to write a piece of code which re enables ctrl c and ctrl v on a paticular page. Here is the source: Code: function disableKeys() { switch ( event.keyCode ) { case 88: //Capture X case 67: //Capture C case 86: //Capture V case 65: //Capture A case 70: //Capture F case 83: //Capture S case 69: //Capture E case 73: //Capture I case 72: //Capture H if (window.event.ctrlKey) { event.cancelBubble = true; event.keyCode = 578; event.returnValue = false; } break; } } I'm sorry I'm not very familiar with html. I figured I could just change the returnvalue to true but it didn't seem to work. Hello, I'm working on putting a partial lexicon of a language online and want to install a search bar at the top. The search should function sort of as "ctrl+f" by only picking up the entries that match with the search item. However, unlike an actual ctrl+f search, I don't want the matches to be highlighted one by one as the user has to continuously press "next." Instead, as soon as the user presses "search," all of the entries on the lexicon should disappear except those that match with the search term. Further information: I've mostly been using HTML and CSS to build this lexicon. All of my entries are in individual div elements and have individual div class names. Can anyone help, or refer me to an existing tutorial? Thanks! I am trying to use the cut and paste OnMouseover Slideshow that is featured at the JavascriptKit.com. I'm getting a line error code which reads "Line:81 Error: Expected ';' I have tried everything I can think of to eliminate this error...seems I know just enough to be dangerous, not enough to debug. Can someone please help me? Or at least tell me if there's someplace specific in between the script tags or elsewhere that I need to look? Killing me in Kentucky, Pam do anyone know how do 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. Thanks For some reason after I modified the events.js script for my events, the events.js is not being read. I have reloaded the page, cleared the cache, and reinstalled the .js file. What is wrong? Is there a way to have the websites open in new windows? I've tried the standard ways, but script doesn't work when I change it. Does anyone know what and where in the script I can add for opening in new windows. Thank you The script is shown on this page: http://www.javascriptkit.com/script/cut181.shtml http://www.javascriptkit.com/script/...megamenu.shtml this drop down menu works great however, if you hit control F5 in firefox, sometimes (alot) will display incorrectly). i have included two images in here just to show what i'm talking about. if you know how to fix this. please let me know. thank you and really appreciate it. Hi guys (and ladies) I am a bit stuck and hope this community might shine a light, or even better can supply me with a solution. I want to do the following: - Having an ordinary webpage containing links - I will link the links with files (word processing files , MS Word, Open Office writer, wordpad or similar) - Now when clicked on the link I want the 'system' to copy the contents of the linked file to the windows clipboard, so when clicking paste, the text from the file is pasted wherever I want. To make clear, I don't want any word processing app to open, just click the link and paste where it needs to be. Possible?? MOST LIKELY but I have no clue how. Any chance someone might know the answer??? I am looking forward to the replies! Thanks PvL In a <textarea ..., the user can do this: 1) copy some text from somewhere; 2) right-mouse click on the textarea, from the floating menu, select the Paste, the text is pasted in the textarea. How can I detect the action of the Paste menuitem being clicked (on IE and Firefox, respectively)? Thanks Scott Hi everyone, I've been trying to amend this so that when I paste text in with a mouse it changes to uppercase automatically. Does anyone know how this can be done? Code: <html> <head> <script type="text/javascript"> function upperCase(x) { var y=document.getElementById(x).value; document.getElementById(x).value=y.toUpperCase(); } </script> </head> <body> Enter your name: <input type="text" id="fname" onchange="upperCase(this.id)" /> </body> </html> Thanks Hello everyone! I'm using Cut & Paste Plus Size image viewer ( http://www.javascriptkit.com/script/...geviewer.shtml ) , but I noticed some problem. When the large image is loaded initially, it's not always positioned on the center of the page. After that the script works just fine, until the browser is re-started. There is link to my page: http://www.accentironwork.com/yard%20decorations.html Script code is the http://www.accentironwork.com/plusimageviewer.js http://www.accentironwork.com/plusimageviewer.css I hope some body can help me. Thanks in advance! Hi, I am wondering, is there any method that can copy a file(.pdf) from server and paste it in the local drive while the file(.pdf) in the local drive is reading by users ? P/S : In Windows, the users are not allow to edit or replace the file if it's being read. Requirements : The users must read the file in local drive after copy from the server. 2 methods been tried : 1. I tried the method which make the javascript to close the browser(IE) first, then copy and replace the file but after the browser is close, everything stopped. 2. Then, I also tried to reopen the file from server first, then only I copy the file from server and replace the local file again but the problem exists again. Even though the local file is closed and file from server is open, the system just doesn't allow me to copy and replace the local file. Why ? Can anyone give me some suggestion or advice please ? Really need help on this issue. Hello, I have a question about the cut and paste javascript events calendar at http://www.javascriptkit.com/script/...calendar.shtml Is there any way to add links to the event description that appears in the box below the calendar? Thanks for your help. Yeah, it's that internal search engine script again. But before you click away, I'd like to ask whether anyone can solve a problem I've come up against... I have minimally changed the script to present results with a clickable url (this is my attempt at creating an image search engine, hence having to use this method). The problem I have suddenly encountered however is that the urls, while they read complete, they only link one directory deep into my website. For example: Reads as: http://www.mysite.com/search/set1/doctor.jpg Link is: http://www.mysite.com/search As you will see, I've omitted using the numbering array and have rearranged the order in which the values for how the search results are called. Code: if (include_num == 1) { document.write(a + 1, '. <a href="', os[0], '">', os[1], '</a><br>', os[2], '<p>'); } else { document.write('<a href="', os[0], '">', os[1], '</a><br>', os[2], '<p>'); } It is with this second point that I fear I have caused the damage. Code: // ---------- script properties ---------- var include_num = 0; var bold = 1; // ---------- sites ---------- var s = new Array(); s[0] = "^this will be added soon/form.html^Click to view image^"; s[0] = "^this will be added soon/doc.txt^Click to view image^"; s[0] = "^http://mysite.net/archive/Gliding/folderthumb.jpg^Click to view image^"; s[0] = "^this will be added soon/doctor.txt^^"; // ---------- end of script properties and sites ---------- var cookies = document.cookie; var p = cookies.indexOf("d="); if (p != -1) { var st = p + 2; var en = cookies.indexOf(";", st); if (en == -1) { en = cookies.length; } var d = cookies.substring(st, en); d = unescape(d); } var od = d; var m = 0; if (d.charAt(0) == '"' && d.charAt(d.length - 1) == '"') { m = 1; } var r = new Array(); var co = 0; if (m == 0) { var woin = new Array(); var w = d.split(" "); for (var a = 0; a < w.length; a++) { woin[a] = 0; if (w[a].charAt(0) == '-') { woin[a] = 1; } } for (var a = 0; a < w.length; a++) { w[a] = w[a].replace(/^\-|^\+/gi, ""); } a = 0; for (var c = 0; c < s.length; c++) { pa = 0; nh = 0; for (var i = 0; i < woin.length; i++) { if (woin[i] == 0) { nh++; var pat = new RegExp(w[i], "i"); var rn = s[c].search(pat); if (rn >= 0) { pa++; } else { pa = 0; } } if (woin[i] == 1) { var pat = new RegExp(w[i], "i"); var rn = s[c].search(pat); if (rn >= 0) { pa = 0; } } } if (pa == nh) { r[a] = s[c]; a++; } } co = a; } if (m == 1) { d = d.replace(/"/gi, ""); var a = 0; var pat = new RegExp(d, "i"); for (var c = 0; c < s.length; c++) { var rn = s[c].search(pat); if (rn >= 0) { r[a] = s[c]; a++; } } co = a; } function return_query() { document.jse_Form.d.value = od; } function num_jse() { document.write(co); } function out_jse() { if (co == 0) { document.write('Your search did not match any images currently on file.<p>Make sure all keywords are spelt correctly.<br>Alternatively, view the Unknown Section of the Archive and help us put a name and date to your memories.'); return; } for (var a = 0; a < r.length; a++) { var os = r[a].split("^"); if (bold == 1 && m == 1) { var br = "<b>" + d + "</b>"; os[2] = os[2].replace(pat, br); } if (include_num == 1) { document.write(a + 1, '. <a href="', os[0], '">', os[1], '</a><br>', os[2], '<p>'); } else { document.write('<a href="', os[0], '">', os[1], '</a><br>', os[2], '<p>'); } } } Because of the nature of the site (it will have over 600 images eventually), my level of understanding and the obviously limitations with this script, I'm looking for a solution that doesn't require a different edit for each entry. So far I have been able to simply drop a block of urls into this script (having planted a .php script to get the image directory listing) and then 'replace all' text that needs to be edited. In short, how do I ensure that the hyperlink for the url that is returned in the search query is full and not truncated to the first directory? ANY help in the matter would be really appreciated. Thank you in advance, Sam hi, i need to be able to allow a user to past into an editable div (via whatever the user chooses: right-click and paste, shortcut key, etc), but i want to discard formatting and only take the plain text. i can't use a textarea since the div will allow basic formatting (bold and italic) if applied by user-initiated events. the onbeforepaste event looked promising, but according to quirksmode the support is so limited as to be unusable. i searched the board, so apologies if this has been asked and answered. tyia for any suggestions. Hi all, I am having problems with a script 'Cut & Paste CSS Horizontal List Menu' from http://www.javascriptkit.com/script/...stopmenu.shtml It works on my site with Firefox but not IE 8. My site url is http://www.bridgepoint-llp.co.uk/ I would be grateful for any help anyone could supply Hello, 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. Can anyone, 1. suggest why it is behaving this way? 2. suggest a work around to allow it to work on FF? Hello, I'm hoping someone can help me with a problem. I have downloaded and installed the Cut & Paste BackBox Image Viewer: http://www.javascriptkit.com/script/...ox/index.shtml When I click the image to activate the script, the pop-up displays at the very bottom left of the page. It's also not formatted correctly. For instance, I'm unable to see the Auto and Close buttons, the caption information is at the top and things are just generally out of whack. Everything seems to be in the correct directories. I've tried cutting and pasting the script into a plain document and the same thing happens. I'm working on this locally, so I don't have a live example. Can someone please help. I've been working at this for two days and just about wanna scream. lol Thank you in advance for your response. Hello, 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: Quote: <form name=formName> <iframe name=frameName src="<a href=http://www.google.com onclick="parent.document.forms['formName'].elements['fieldName'].value = 'do you right';" return false;">Click Here To Get Done Right</a> " width="800" height="400" ></iframe><br><br> <input type="text" id="fieldname" size="95" name="t2"> </form> letchev |