Ask Question Forum:
Model Library:2025-02-08 Updated:A.I. model is online for auto reply question page
C
O
M
P
U
T
E
R
2
8
Show
#
ASK
RECENT
←
- Underline
- Bold
- Italic
- Indent
- Step
- Bullet
- Quote
- Cut
- Copy
- Paste
- Table
- Spelling
- Find & Replace
- Undo
- Redo
- Link
- Attach
- Clear
- Code
Below area will not be traslated by Google,you can input code or other languages
Hint:If find spelling error, You need to correct it,1 by 1 or ignore it (code area won't be checked).
X-position of the mouse cursor
Y-position of the mouse cursor
Y-position of the mouse cursor
Testcursor
caretPos
Attachment:===
Asked by duncanb7
at 2024-08-19 11:38:25
Point:500 Replies:11 POST_ID:828752USER_ID:11059
Topic:
JavaScript;Hypertext Markup Language (HTML);jQuery
I would like to do bold text on the my selected text on <textarea> tag
and I search a lot of in google and found similar topic as follows links
but it doesn't works after click the <a> Bold link to function replaceST();
What I just replace the text "aaaa" and bold text with 'aaaa" at the same location
after text selection in the first textarea tag.
So it should be similar to the javascript code result
document.getElementById('texthtml').innerHTML="<br>aaaa</b> for bold tag;
Please advise how to achieve this
Duncan
http://stackoverflow.com/questions/3997659/replace-selected-text-in-contenteditable-div
and I search a lot of in google and found similar topic as follows links
but it doesn't works after click the <a> Bold link to function replaceST();
What I just replace the text "aaaa" and bold text with 'aaaa" at the same location
after text selection in the first textarea tag.
So it should be similar to the javascript code result
document.getElementById('texthtml').innerHTML="<br>aaaa</b> for bold tag;
Please advise how to achieve this
Duncan
http://stackoverflow.com/questions/3997659/replace-selected-text-in-contenteditable-div
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"><html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <title>Title</title> </head><script type="text/javascript">function replaceST(replacementText) {alert(document.getElementById('texthtml').innerHTML); var sel, range; if (window.getSelection) { sel = window.getSelection(); if (sel.rangeCount) { range = sel.getRangeAt(0); range.deleteContents(); range.insertNode(document.createTextNode(replacementText)); } } else if (document.selection && document.selection.createRange) { range = document.selection.createRange(); range.innerHTML = replacementText; }}</script><body><div><a href="javascript:replaceST( document.getElementById('texthtml').innerHTML);">Bold</a><div>Testing bold text into html</div><textarea style="width:100px;height:100px" id="texthtml">aaaa</textarea><textarea style="width:100px;height:100px" id="junk">Trash</textarea></div></body></html> 1:2:3:4:5:6:7:8:9:10:11:12:13:14:15:16:17:18:19:20:21:22:23:24:25:26:27:28:29:30:31:32:33:34:35:36:37:38:39:40:41:
Author: duncanb7 replied at 2024-08-20 22:11:09
Thanks for your reply and useful links
Duncan
Duncan
Expert: ModeIT replied at 2024-08-20 20:02:45
object for asker request
Author: duncanb7 replied at 2024-08-20 02:56:26
Dear Admin/Moduator,
I am so sorry I clicked the wrong button to close this thread,
Please re-open for the scoring again
Thanks
Duncan
I am so sorry I clicked the wrong button to close this thread,
Please re-open for the scoring again
Thanks
Duncan
Author: duncanb7 replied at 2024-08-20 02:38:07
I've requested that this question be closed as follows:
Accepted answer: 0 points for duncanb7's comment #a39422836
Assisted answer: 166 points for padas's comment #a39421172
Assisted answer: 167 points for padas's comment #a39421263
Assisted answer: 167 points for padas's comment #a39422241
for the following reason:
thanks for your attached link in this thread
Accepted answer: 0 points for duncanb7's comment #a39422836
Assisted answer: 166 points for padas's comment #a39421172
Assisted answer: 167 points for padas's comment #a39421263
Assisted answer: 167 points for padas's comment #a39422241
for the following reason:
thanks for your attached link in this thread
Author: duncanb7 replied at 2024-08-20 02:35:13
Finally solved it by Jquery and cover IE -version ,FF,Chrome;
insertTag('#testid', 'b', 'b');
insertTag('#testid', 'b', 'b');
function insertTag(tb,tag,tag2){if(document.selection&&document.selection.createRange){ //IEvar SelectedString = document.selection.createRange().text;var ReplaceString = "<"+tag+">"+SelectedString+"</"+tag2+">";document.selection.createRange().text = ReplaceString;}else{var obj=$(tb); //FF, Chrome, etc.if (typeof obj.getSelection().text != 'undefined' && obj.getSelection().text!=""){ var before, after, stext; before= obj.val().substring(0, obj.getSelection().start) stext = obj.val().substring(obj.getSelection().start, obj.getSelection().end) after = obj.val().substring(obj.getSelection().end, obj.val().length) obj.val( before+"<b>"+stext+"</b>"+after); obj.focus();}}} 1:2:3:4:5:6:7:8:9:10:11:12:13:
Assisted Solution
Expert: Scott Fell (padas) replied at 2024-08-19 20:16:01
166 points GOOD
Then you need to use a markdown tool such as what you use when you post your response here, or a full or lightweight wysiwyg a I have already posted. An example of a markdown box similar to what you use here would be http://markitup.jaysalvat.com/home/
Author: duncanb7 replied at 2024-08-19 12:58:37
Did you do the Bold text example code before whatever in what tag ?
If yes, do you mind to share your javascript code with us ?
The action is just when you drag or select a text and respond
bold text in a tag with html format such as ,<b>aaaa</b>
And the viewers will see the text in bold
Duncan
If yes, do you mind to share your javascript code with us ?
The action is just when you drag or select a text and respond
bold text in a tag with html format such as ,<b>aaaa</b>
And the viewers will see the text in bold
Duncan
Assisted Solution
Expert: Scott Fell (padas) replied at 2024-08-19 12:25:37
167 points GOOD
Take a look at these scripts. If you are making a demo of code, these are pefect http://www.webdesignbooth.com/9-useful-javascript-syntax-highlighting-scripts/
Author: duncanb7 replied at 2024-08-19 12:12:30
I don't need HTML editor, I need to know how to do it for tutorial or example code
with just simple javascript action or code for Bold text
with just simple javascript action or code for Bold text
Author: duncanb7 replied at 2024-08-19 12:01:06
Could you make me example code for demo or tutorial , I don't care whether it is
textarea tag or div tag ?
textarea tag or div tag ?
Accepted Solution
Expert: Scott Fell (padas) replied at 2024-08-19 11:58:49
167 points GOOD
What are you using the text area for? Obviously you can't just make text some text bold and other text not.
Your options would be to use a wysiwyg editor. If you are already using tinymce that could be a good choice. Otherwise, here is a list of lighter wysiwyg text area replacement. https://github.com/cheeaun/mooeditable/wiki/Alternative-Javascript-WYSIWYG-editors
The other option is to use a div, style inside the div, then at the time you want to submit the form, use javascript/jquery to convert the div to a text area or at least the text inside of the div can be posted via ajax if you go that route.
Your options would be to use a wysiwyg editor. If you are already using tinymce that could be a good choice. Otherwise, here is a list of lighter wysiwyg text area replacement. https://github.com/cheeaun/mooeditable/wiki/Alternative-Javascript-WYSIWYG-editors
The other option is to use a div, style inside the div, then at the time you want to submit the form, use javascript/jquery to convert the div to a text area or at least the text inside of the div can be posted via ajax if you go that route.