Jump to content

Adding bbcode to links via checkbox


sford999
Go to solution Solved by 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]

Edited by sford999
Link to comment
Share on other sites

  • Solution

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');
		});
	});
},
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.