theflyingminstr
07-20-2009, 02:12 PM
Hi the script at the bottom appends a text area with info onclick (ref:http://www.codingforums.com/showthread.php?p=838162).
I wanted to know if it's possible to have a function (possible within the existing one?) that replaces text as well.
Something like this format would be perfect for what I'm tring to do:
<a href="#" onclick = "check('Replace this text', 'With this in the textarea')">Click Me to replace</a><br/>
Original Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta content="text/html; charset=utf-8" http-equiv="Content-Type" />
<title>Onclick Textarea</title>
<script type="text/javascript">
function check(txt) {
var obj=document.form1.textarea1;
if(obj.value.search(txt)==-1) {
obj.value+=txt + "\n";
}
else {
if (txt !='This is some more text which cannot be deleted ') {
obj.value=obj.value.replace(txt,"");
obj.value=obj.value.replace(/\.*(\r|\n)+/g,"\n")
}
}
}
</script>
</head>
<body>
<form name="form1">
<textarea rows="10" cols="40" name="textarea1"></textarea>
<br/><br/>
<a href="#" onclick = "check('This is some long-winded text ')">Click Me 1</a><br/>
<a href="#" onclick = "check('This is some more text which cannot be deleted ')">Click Me 2</a><br/>
<a href="#" onclick = "check('This is yet more pointless text ')">Click Me 3</a>
<!--
<a href="javascript:check('This is some long-winded text ')">Click Me 1</a><br/>
<a href="javascript:check('This is some more text which cannot be deleted ')">Click Me 2</a><br/>
<a href="javascript:check('This is yet more pointless text ')">Click Me 3</a>
-->
</form>
</body>
</html>
Thanks!
I wanted to know if it's possible to have a function (possible within the existing one?) that replaces text as well.
Something like this format would be perfect for what I'm tring to do:
<a href="#" onclick = "check('Replace this text', 'With this in the textarea')">Click Me to replace</a><br/>
Original Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta content="text/html; charset=utf-8" http-equiv="Content-Type" />
<title>Onclick Textarea</title>
<script type="text/javascript">
function check(txt) {
var obj=document.form1.textarea1;
if(obj.value.search(txt)==-1) {
obj.value+=txt + "\n";
}
else {
if (txt !='This is some more text which cannot be deleted ') {
obj.value=obj.value.replace(txt,"");
obj.value=obj.value.replace(/\.*(\r|\n)+/g,"\n")
}
}
}
</script>
</head>
<body>
<form name="form1">
<textarea rows="10" cols="40" name="textarea1"></textarea>
<br/><br/>
<a href="#" onclick = "check('This is some long-winded text ')">Click Me 1</a><br/>
<a href="#" onclick = "check('This is some more text which cannot be deleted ')">Click Me 2</a><br/>
<a href="#" onclick = "check('This is yet more pointless text ')">Click Me 3</a>
<!--
<a href="javascript:check('This is some long-winded text ')">Click Me 1</a><br/>
<a href="javascript:check('This is some more text which cannot be deleted ')">Click Me 2</a><br/>
<a href="javascript:check('This is yet more pointless text ')">Click Me 3</a>
-->
</form>
</body>
</html>
Thanks!