how to get the name of the parent element of the cursor positioned using javascript in html/jsp
I need to get the element name(i.e. text area name where the cursor positioned), and pass the name to the server then when it is back I need to pass thru the url for anchoring to the position of the element.
every text/textarea have its own anchor names defined in a form i need to know where the cursor was positioned be开发者_如何学Cfore form submit or perform any action on the form or when form refresh i need to refer to the last edited element.
Note: Iam using jsp/struts tags in the form
Please provide your suggestion on this as how i can achieve this. am in urgent.
thanks in advance.
onfocus, onclick and onchange are not identifying/working for my textareas, because Iam using tinyMCE as the RTE feature.
please let me know any alternatives available to provide this functionality for my textareas.
Try something like this:
<input type="hidden" id="lastedited" value="" />
Then for each textarea:
<textarea id="field2"
onfocus="document.forms[0].lastedited=this.id">blah</textarea>
This will set the hidden field with the id of the last textarea the cursor was in, and pass that hidden field to the server.
I did not assume you had JQuery running... if you do, the Javascript above can be simplified somewhat.
Edit: TinyMCE Editor instances have their own OnChange events you can add a handler for, something like this:
var ed = new tinymce.Editor('textareaid', { blah blah blah });
ed.onChange.add(function(ed, e) { document.forms[0].lastedited=ed.getElement().id });
OnChange is the best event in this case, since TinyMCE doesn't have onfocus/onblur events, and tabbing into an editor won't result in OnClick.
精彩评论