Welcome Guest, Not a member yet? Register   Sign In
javascript code escaping
#1

[eluser]Michael;[/eluser]
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:

Code:
[removed]
  $(document).ready(function(){
    $("#example > ul").tabs();
  });
[removed]

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.

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

and in "common":

Code:
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]

This:

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

Results in this (taken from view source):

Code:
[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.




Theme © iAndrew 2016 - Forum software by © MyBB