Friday 27 September 2013

Set focus after a particular item in an inputbox in jquery/javascript

Set focus after a particular item in an inputbox in jquery/javascript

So lets say I have an input box that looks something like this:
<input id="fuzzyname" value="" placeholder="&Fuzzybear">
I want to use javascript/JQuery so that when I click in that input box it
will put the cursor after the & and the placeholder becomes the value in
the input box.
This is kind of what I have so far:
$("#fuzzyname").focus(function () {
var value = $(this).attr("placeholder");
var symbol = "&";
var cursorIndex = value.indexOf(symbol);
//This is where I want to output the value into the inputbox with
the cursor after cursorIndex
});

No comments:

Post a Comment