Jump to content

Adding bbcode to links via checkbox


sford999

Recommended Posts

I have the following code which is used when a user checks a checkbox, or multiple checkboxes, the checkbox value(s) is passed to a textarea.

"fnDrawCallback": function()
{
    $('input[type=checkbox]').click(function()
    {
        $('textarea[name=links]').val(
        $('input[type=checkbox]:checked').map(function()
        {
            return $(this).val();
        }).toArray().join("\n"));

        $('textarea[name=bbcode]').val(
        $('input[type=checkbox]:checked').map(function()
        {
            return $(this).val();
        }).toArray().join("\n"));
    }
    );
},


What I want to do is add the or

 before and after the passed url, but I'm completely new to jQuery and no idea how to do it.

 

As it is now, the checkboxes pass the URL but I want it to pass it to another text area with bbcode

 

EG:

Textarea 1

http://www.domain.com

 

Textarea 2

[url ]http://www.domain.com[/url]

Link to comment
https://forums.phpfreaks.com/topic/277260-adding-bbcode-to-links-via-checkbox/
Share on other sites

I figured it out as i changed the code to:

"fnDrawCallback": function() 
{
	$('input[type=checkbox][name=links]').click(function()
	{
		$('textarea[name=links]').text('');
		$('input[type=checkbox][name=links]:checked').each(function()
		{
			$('textarea[name=links]').append( $(this).val() + '\n');
		});
	});

	$('input[type=checkbox][name=links]').click(function()
	{
		$('textarea[name=bbcode]').text('');
		$('input[type=checkbox][name=links]:checked').each(function()
		{
			$('textarea[name=bbcode]').append('[code]' + $(this).val() + '[/code] \n');
		});
	});
},

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.