javascript - Safe way to store data for button clicks -


i trying find out safest way store data use when user clicks on button.

i know can store data in attributes(either value attribute or data- attribute) of button tag so:

<button type="button" value="1" data-value="1">click me!</button> 

but problem user(probably advanced users) can manipulate value firebug or other app , click button , send on different data. understand need check input before try sent data.

i found out use jquery's .data() attach data dom elements, seems bit more useful. i'm not sure how data stored, assume harder manipulate.

what got me interested in question when looking through soundcloud's code in firebug, saw none of "like" buttons had data attached buttons. tried deleting/manipulating elements/data , buttons still worked. got me thinking using similar process jquerys data() doing.

i want know if there safer way store data or way user can't manipulate data before clicking button.

consider function:

function setupprivatedata(element) {   var private = 1;    element.setprivate = function ( d ) { private = d; }   element.getprivate = function ( ) { return private; } } 

when called dom element add 2 methods it: .setprivate(val) , .getprivate().

these only methods allow access , modify private variable associated element.


Comments

Popular posts from this blog

python - pip install -U PySide error -

arrays - C++ error: a brace-enclosed initializer is not allowed here before ‘{’ token -

cytoscape.js - How to add nodes to Dagre layout with Cytoscape -