|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
Add <b></b> tags to selected text in a textarea
I have a simple form like so:
PHP Code:
I would like to create some javascript to do the following - when the user clicks the "BOLD" button, the selected text gets a "<b>" and a "</b>" wrapped around it. Sort of like formatting text on this forum. (For some reason I can't see the vBulletin JS that's accomplishing the similar task) Thanks in advance! |
|
#2
|
||||
|
||||
|
here's some code i've created to do the job on some of my sites, i'm not sure it's the best way to do it, but it does the job
PHP Code:
goran |
|
#3
|
|||
|
|||
|
Thanks, Goran.
Unfortunately I could only get that code to work in IE. It fails in Firefox: 'document.selection' has no properties. I'll plug away a bit and see what I can come up with. |
|
#4
|
|||
|
|||
|
For Mozilla and friends:
Code:
function formatText(el,tagstart,tagend) {
if (el.setSelectionRange) {
el.value = el.value.substring(0,el.selectionStart) + tagstart + el.value.substring(el.selectionStart,el.selectionEnd) + tagend + el.value.substring(el.selectionEnd,el.value.length)
}
else {
// IE code here...
}
}
..
<input type="button" value="BOLD" onclick="formatText(document.getElementById('myta'),'<b>','</b>')"/>
<textarea id="myta" rows="10" cols="30"></textarea>
<input type="submit" value="SUBMIT" />
</form>
Hope this helps, Jeroen |
|
#5
|
|||
|
|||
|
Thanks - you rock.
Still doesn't work in Safari, but Google searches reveal that this is a limitation of Safarai (and Konqueror), which does not provide a programmatic way of inserting a cursor in a textarea. |
|
#6
|
|||
|
|||
|
BOLD doesn't appear as bold in textarea
I have been trying to look a wayaround to solve somewhat similar problem, but it seems like bold tag appears in coding and not word doesn't appear to be bold in the textarea. Please tell me does textarea does even support rich formatting??
is there any way around for this problem? how does all those web text editors work out there? Quote:
|
|
#7
|
||||
|
||||
|
You need a JavaScript script to do that. Check out these:
http://tinymce.moxiecode.com/ http://openwebware.com/products/openwysiwyg/ Xinha: The Community-built Open Source Online WYSIWYG HTML Editor http://www.fckeditor.net/
__________________
Spreading knowledge, one newbie at a time. Learn CSS. | PHP includes | X/HTML Validator | CSS validator | Dynamic Site Solutions Design/program for Firefox (and/or Opera), apply fixes for IE, not the other way around. I'm looking for new clients. |
|
#8
|
|||
|
|||
|
As of today, a year later after this post. The same code for mozilla browers does work in safari.
|
![]() |
| Viewing: Dev Shed Forums > Web Design > JavaScript Development > Add <b></b> tags to selected text in a textarea |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|