Banner

Sponsor

Login


Welcome Back!
Guest
Guest

Register

Lost your password?

68 users online



Manipulating a string from a Prompt in Javascript

Manipulating a string from a Prompt in Javascript

Currently viewing this thread: 1 (0 members and 1 guests)


andymills

andymills

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? Wink

eljaysun

eljaysun

Neverside Newbie
Status: Offline!
Code:

<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!

___________________

http://image.eljaysun.com/hosted/neversidian_small.gif
Portfolio - Blog | Posts: RSS
Join me in Neverside's Photography Discussion Channel: #photo

Quick Jump:

Main Navigation


Site & Graphic Design by Aeon Tan
Developed by Jeremie Pelletier & Scott Roach


NeverAPI generated this page in 0.0164 seconds.