user43153 user43153 - 8 months ago 36
HTML Question

Passing values into a external function JQuery

I tried to create external general function for all my document. That function I want to use "this" method to work inside process of function and that "this" value come from difference buttons. But this code is not working for me. how to solve it out.

jQuery Code:

function myFunction(e){
var inp = $(this).val(), target =, position = target.selectionStart;
inp = inp.replace(/a/g, "A");
inp = inp.replace(/i/g, "I");
inp = inp.replace(/u/g, "U");
inp = inp.replace(/e/g, "E");
$(this).get(0).setSelectionRange(position, position );

Send the value to external function using jQuery


HTML Code:

<form name="inputform">
<input class="Search" type="text" autofocus name="searchbox" id="Search" style="width:800px; height:200px;">

If I put directly text box id it is working fine.


You don't need to pass #Search as argument of myFunction like myFunction('#Search'). You can do it simply like following.