Jump to content

txtarea tests


rarebit

Recommended Posts

Hi, can anyone test this with IE please? (or other browsers, i've tested with FF and Opera)

 


<script type="text/javascript">
function tester(s)
{
var txtbox = document.myform.post;
var begin = txtbox.value.substr(0, txtbox.selectionStart);
var end = txtbox.value.substr(txtbox.selectionEnd);
txtbox.value = begin + s + end;
document.myform.post.focus();
}
</script>

<a href='javascript:tester("world")'>tester</a><br>

<form name='myform'>
<textarea cols="64" rows="12" name="post">HELLO!</textarea>
</form>

 

Just click your cursor in the middle and click the link!

Link to comment
https://forums.phpfreaks.com/topic/104641-txtarea-tests/
Share on other sites

Looks good, I would just add one line to the function to make it this:

function tester(s)
{
  var txtbox = document.myform.post;
  var begin = txtbox.value.substr(0, txtbox.selectionStart);
  var end = txtbox.value.substr(txtbox.selectionEnd);
  txtbox.value = begin + s + end;
  txtbox.selectionEnd = txtbox.selectionStart = begin.length + s.length;
  document.myform.post.focus();
}

Link to comment
https://forums.phpfreaks.com/topic/104641-txtarea-tests/#findComment-535690
Share on other sites

is this related to adding a text to a text area ??

 

I want for example when an event is triggered to write something where the txt cursor in the text area is pointing ..

 

for example like the buttons above ( B , I , ...) they add the bbcode where the cursor is pointing ..

 

please I need a clear example

 

thx

Link to comment
https://forums.phpfreaks.com/topic/104641-txtarea-tests/#findComment-536697
Share on other sites

That's what this does, but it doesn't wrap highlighted code, just replaces it or inserts it if nothing is selected.

 

If you wanted to wrap some text, the bit you want to wrap is the difference between 'begin' and 'end'. I haven't got access to my stuff right now but i'll post it soon...

Link to comment
https://forums.phpfreaks.com/topic/104641-txtarea-tests/#findComment-537109
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.