I want to bind a function to all the textarea and want to run it whenever a key gets pressed.
function fx(docid)
{
$('#'+docid).val=encodeURIComponent($('#'+docid).val());
//document.getElementByID('docid').value = encodeURIComponent(document.getElementByID('docid').value);
}
Note: the page will have different textarea, I want a single function to do the same job for all the textarea. I don’t want to hard code the event with the textarea <textarea onkeydown="..." />
Edit
I want to trigger the function on multiple events, thats on keypress, keydown,click
Just pass in
textareaas the selector. If you want it to trigger for text inputs as well then usetextarea, input[type="text"]for the selector:Of course, if you run your function as written it will double, triply, etc encode the value, so you’ll need to write a function that leaves %## values alone.