CodeIgniter Forums
javascript code escaping - Printable Version

+- CodeIgniter Forums (
+-- Forum: Archived Discussions (
+--- Forum: Archived Development & Programming (
+--- Thread: javascript code escaping (/thread-12364.html)

javascript code escaping - El Forum - 10-16-2008

I've done a google search and it turned up a lot of information on the subject, but being fairly new to javascript in general I'm still having some issues and I thought I might get some input from the community and see where that leads... more often than not, to a solution.

I have the following snippet of javascript (jQuery) that I need to include on pages that I intended to use tabs on:

    $("#example > ul").tabs();

The problem is two-fold. First I need to be able to "include" the code and second, I want to pass a variable into the code as well.

$data['extra_header'] = $this->common->jstabs($var);

and in "common":

function jstabs(){
        return $str = "[removed]$(document).ready(function(){$("#".$var." > ul").tabs();});[removed]";

$var is simply the html id of the tab-set so if I ever need to use multiple sets of tabs on a page that option is available.

Normal php escaping results in valid php code, but invalid [removed]


return $str = "[removed]$(document).ready(function()\{$(\"#".$var." > ul\").tabs()\;\});<\/script>";

Results in this (taken from view source):

[removed]$(document).ready(function()\{$("# > ul").tabs()\;\});<\/script>

and this obviously does not work... n fact, currently is resulting in a blank white screen.

Any help that anyone can provide would be greatly appreciated.