Inserting text into a textarea
I currently have this HTMl code...
HTML Code:
<p> <a class="insertCode" href="#" > < p> < /p> </a> | <a class="insertCode" href="#" > < a target=" " href=" " > < /a> </a> | <a class="insertCode" href="#" > < h1> < /h1> </a> </p>
and this javascript...
HTML Code:
<script language="javascript" type="text/javascript" >
$('a.insertCode').click(function()
{
var htmltag = $(this).text();
$('#codeArea').val($('#codeArea').val()+htmltag);
return false;
})
</script>
I am trying to make those links into "buttons" that will insert code into my textarea. So far I have nothing happeneing, even the links still work...
I notice you don't have your script wrapped in the customary document ready function - in this case you need to make sure that your html is coded before your script...
Code:
<body>
<p><a class="insertCode" href="#"><p></p></a> | <a class="insertCode" href="#"><a target="" href=""></a></a> | <a class="insertCode" href="#"><h1></h1></a></p>
<textarea id="codeArea"></textarea>
<script type="text/javascript">
$('a.insertCode').click(function()
{
var htmltag = $(this).text();
$('#codeArea').val($('#codeArea').val()+htmltag);
return false;
})
</script>
</body>
Yeah, this is the way I have it, but no dice.
Even tried this...
HTML Code:
<script type="text/javascript" >
$(function(){
$('a.insertCode').bind("click",function()
{
var htmltag = $(this).text();
$('#codeArea').val($('#codeArea').val()+htmltag);
return false;
});
});
</script>
Last edited by Dragonfire2008; 05-07-2012 at 10:28 PM .
the code I posted works for me. must be something else.
Ok I got it to work, for some reason the textarea has to come after the "links", otherwise it won't work...
That's ok, I can work with it, thanks
Last edited by Dragonfire2008; 05-07-2012 at 10:41 PM .
this works for me in IE, FF and Chrome...
Code:
<body>
<textarea id="codeArea"></textarea>
<p><a class="insertCode" href="#"><p></p></a> | <a class="insertCode" href="#"><a target="" href=""></a></a> | <a class="insertCode" href="#"><h1></h1></a></p>
<script type="text/javascript">
$('a.insertCode').click(function()
{
var htmltag = $(this).text();
$('#codeArea').val($('#codeArea').val()+htmltag);
return false;
})
</script>
</body>
Thread Information
Users Browsing this Thread
There are currently 1 users browsing this thread. (0 members and 1 guests)
Posting Permissions
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
Forum Rules
Bookmarks