views:

66

answers:

2

I am dealing with textarea, and on click of this I am calling one replace function which will remove some specified string in textarea, this is the basic operation.

Expected behavior after clicking on textarea

1) At first click :

  • It should remove specified string from textarea
  • Cursor should come at end of string

2) more than one click : - Cursor should come at where ever user clicks in text area

Below is my replace function....

function replace(id,transFromDb) {
    newStr = $("#"+id).val();
 var len = null;
  if(transFromDb == '') {
   newStr = newStr.replace(Lang.Message27,'');
   newStr = newStr.replace(Lang.Message28,'');

  }
  else {
   newStr = newStr.replace(Lang.Message28,'');
   newStr = newStr.replace(Lang.Message27,'');
  }

  /* change font weight as bold. */
  $("#"+id).css({"fontWeight":"bold"});
  $("#"+id).val(newStr);
}

Assume that Lang.Message is specified string.

It's working above behavior with FF. Facing issue on IE, it always keep cursor position at first.

Please provide any solution....

Thanks in Adavance Pravin

A: 
$("#idOfTextarea").focus(function() {
  replace($(this).attr("id"), "");
});

I'm not sure what the second parameter of replace is receiving, so I've just put an empty string in, you'll have to fill that in yourself.

There's clean and easy code for moving the cursor to the end of the textarea here.

GlenCrawford
A: 

Hey folks thanks a lot for your suggestions...

Here i m facing another conflict that,

I have x y co-ordinates, and I want to set curosr to (x,y position) this location. then how to come up for this solution.

pravin
You shouldn't type an answer to your own question if you have another one. Just edit your original question or comment on an existing anwser.
Marcel Korpel