faqts : Computers : Programming : Languages : JavaScript : Forms : TextAreas/TextFields

+ Search
Add Entry AlertManage Folder Edit Entry Add page to http://del.icio.us/
Did You Find This Entry Useful?

12 of 15 people (80%) answered Yes
Recently 9 of 10 people (90%) answered Yes

Entry

can i create a TextField that doesn't allow Paste(and Ctrl+v) but allows users to type in string

May 17th, 2006 16:14
Krunal Bhatt,


<html>
<head>
<script language="javascript">


function onKeyDown() {

  var pressedKey = String.fromCharCode(event.keyCode).toLowerCase();

  if (event.ctrlKey && (pressedKey == "c" || 
                        pressedKey == "v")) {
    // disable key press porcessing
    event.returnValue = false;
  }

} // onKeyDown

</script>
</head>

<body oncontextmenu="return false;" ondragstart="return false;" 
onmousedown="return false;">

<form name="aForm">
<input type="text" name="aText" onkeydown = "onKeyDown()">
ajadflkja kljdf pao klasdfkjeiklj oi adfk iowkse d f ldjfpq dfae sdhga 
</form>
</body
</html>