
April 15th, 2006
06:15 PM
Neverside Newbie
Status: Offline!
Manipulating a string from a Prompt in Javascript
Hi All
I'm working on some Content-Management stuff again and I'm trying to write my own formatting stuff. I have a series of buttons which when clicked show a prompt which tells the user to type in the text they wish to appear, say, Bold. What I want to do, is grab whatever text they've typed into the prompt box, place it between a <b> and a </b> tag, and insert it into the text area of the form at the end of whatever has already been typed into that text area. When the Bold button is clicked, it calls a function called "textbold" which brings up the prompt. I've given the text area the id "text".
Can someone help me do the rest please? 

April 16th, 2006
12:40 AM
Neverside Newbie
Status: Offline!
<script type="text/javascript">
function textBold() {
var textArea = document.theForm.text;
var currentValue = textArea.value;
textArea.value = currentValue + "<strong>" + prompt("Enter bold text","text") + "</strong>";
}
</script>
...
<a href="#" onclick="javascript:textBold();">Bold text</a>
<form name="theForm">
<textarea name="text">Some text here and </textarea>
</form>
That function will take the text from the input prompt, put it between "<strong>" and "</strong>", and append all of that to the end of the data in the textarea. I hope thats what you were looking for. Good luck!
___________________
Portfolio - Blog | Posts: RSS
Join me in Neverside's Photography Discussion Channel: #photo