4

I am checking my HTML code with Amaya.

I have an error on this line:

<input style="vertical-align:bottom;" type="text" id="doi_id" onkeydown="if (event.keyCode == 13) return false;" onpaste="parsePIIfromDOI();"/>

And for the onpaste, I am getting "Invalid attribute "onpaste"(removed when saving)" error.

I don't know why? Thank you very much for your help.

Milos Cuculovic
  • 19,631
  • 51
  • 159
  • 265

2 Answers2

3

http://reference.sitepoint.com/html/extended-event-attributes/onpaste

"Non-standard event defined by Microsoft for use in Internet Explorer. May work in some other browsers but cannot be reliably used. Compatibility for this non-standard attribute not tested."

Stefan
  • 3,850
  • 2
  • 26
  • 39
  • Thank you for the info Stefan, do you think I should use this method or not? For the mment, works with mozilla and also IE. I don't know for the others. – Milos Cuculovic Sep 11 '12 at 10:23
  • I think is fine, on this link: http://codebits.glennjones.net/editing/getclipboarddata.htm we can see that only opera does not support the onpaste attribute. – Milos Cuculovic Sep 11 '12 at 10:25
  • 1
    @Milos: Google Analytics tells me that about 1% of my website visitors use Opera. I suspect it will be the same for your site. If you are happy with those visitors not having this functionality then you can use it. But you might also consider using jQuery to bind the onpaste event: http://stackoverflow.com/questions/237254/how-do-you-handle-oncut-oncopy-and-onpaste-in-jquery and http://stackoverflow.com/questions/686995/jquery-catch-paste-input/1503425#1503425 – Stefan Sep 11 '12 at 10:31
  • Thank you Stefan, In fact, the page I am creating is for internal use and will be accessed only by some known members I can control (access, browsers etc.). I think that it should be fine for the moment. thank you very much for the jQuerry idea. I will take a look on it. – Milos Cuculovic Sep 11 '12 at 11:09
  • 1
    @Milos: You are welcome. Actually 'normal' javascript (not jQuery) also seems very simple: http://stackoverflow.com/a/546942/888177 – Stefan Sep 11 '12 at 11:48
3

The Amaya editor performs a syntax check using a document type definition, and its built-in repertoire includes only doctypes that do not allow the onpaste attribute. That’s why you get the error message.

There’s probably no way around this message in Amaya. You can use Tools → Change doctype → Remove the doctype or, better, manually change, in Show Source mode, the doctype declaration to <!doctype html>, the HTML5 doctype. But Amaya still keeps checking against the specification it regards as the correct one.

Amaya is an editor (and a testbed browser), not a checker. Use a validator to check your syntax. Then you can use <!doctype html> to specify HTML5. Beware that HTML5 has some oddities, and contrary to popular misconceptions, it is not a pure extension of HTML 4.01. And apparently because Amaya decides to remove the attribute, you would need to use a different editor.

Whether onpaste is useful and safe to use is a different question.

Update (July 2018): Over the years that have passed, onpaste has not become part of official HTML, so a validator issues an error message about it. Yet, support appears to appear e.g. in Chrome. If you need to avoid validation errors (or your editor removes an onpaste attribute), use JavaScript to assign a value to the onpaste property of the element node instead of using an attribute in HTML markup.

Jukka K. Korpela
  • 195,524
  • 37
  • 270
  • 390