sford999 Posted April 24, 2013 Share Posted April 24, 2013 (edited) 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 1http://www.domain.com Textarea 2[url ]http://www.domain.com[/url] Edited April 24, 2013 by sford999 Quote Link to comment https://forums.phpfreaks.com/topic/277260-adding-bbcode-to-links-via-checkbox/ Share on other sites More sharing options...
sford999 Posted April 27, 2013 Author Share Posted April 27, 2013 Anyone? Quote Link to comment https://forums.phpfreaks.com/topic/277260-adding-bbcode-to-links-via-checkbox/#findComment-1426843 Share on other sites More sharing options...
Jessica Posted April 27, 2013 Share Posted April 27, 2013 (edited) In javascript you concatenate strings with + If you have the string you want to add the code to, just do "http://"+url+"" Edited April 27, 2013 by Jessica Quote Link to comment https://forums.phpfreaks.com/topic/277260-adding-bbcode-to-links-via-checkbox/#findComment-1426866 Share on other sites More sharing options...
Solution sford999 Posted April 28, 2013 Author Solution Share Posted April 28, 2013 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'); }); }); }, Quote Link to comment https://forums.phpfreaks.com/topic/277260-adding-bbcode-to-links-via-checkbox/#findComment-1426934 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.