
September 9th, 2004, 12:38 AM
|
 |
Contributing User
|
|
Join Date: Nov 2002
Location: New York City
Posts: 233
Time spent in forums: 1 Day 50 m 19 sec
Reputation Power: 6
|
|
code similar to vbcode or bbcode replacing the textarea
on my site I have a simple form for site administrators to use to add news articles or calendar events to the site. We ran into a problem with someone using html. They forgot to close a tag and it caused some minor problems. We decided to then strip all html from anything people want to post so that can't happen again. However we do want the ability for admins to post links and make text bold and stuff like that. We set up some code to do this. it may works similar to how posting a message here work but, probably a whole lot more simplistic. The only problem we have is when the user clicks the b for bold instead of placing the appropriate code in the textarea where the curser is, it replaces what is already in the textarea. So how can I get the javascript to put in the code in the textarea without replacing the text already there.
here is the code we have in our test form
Code:
<script language="JavaScript">
var display_text=new Array("Test 1","Test 2");
var display_text_a="";
function button_test(display_text_a)
{
document.test.text.value=display_text[display_text_a]+" and "+display_text[display_text_a];
}
function insertcode(display_text_a)
{
document.test.text2.value=display_text[display_text_a]+" and "+display_text[display_text_a];
}
</script>
<form name="test">
<input type="button" name="test" onmouseover="button_test(0)" onclick="insertcode(0)" value="test 1" />
<input type="button" name="test" onmouseover="button_test(1)" onclick="insertcode(1)" value="test 2" />
<input type="text" name="text" disabled>
<textarea name="text2"></textarea>
</form>
|