0

I'm needing to call a plugin that uses a var to work it's self. but I can't get the var cause that can change so... this is what I was trying to do.

var selection = $(".view-your-rescues .cms_textarea,.post-a-rescue .cms_textarea,.edit-account-details .cms_textarea");

if(selection.length > 0 ) {
    selection
        .css({"height":"100","width":"500"})
        .each(function(i) { 
            var eval("hb"+i ) = $(this).htmlbox({
                toolbars:[[
                    "separator","bold","italic","underline","strike","sup","sub",
                    "separator","justify","left","center","right",
                    "separator","ol","ul","indent","outdent"
                ]],
                icons:"silk",
                skin:"red",
                idir:"/uploads/htmlbox/",
                about:false
        });
    });
}

So that is based on this http://htmlbox.remiya.com/cms/demo/iconsets-demo/ where you'll see that that in order to do two you need to have the different vars.

The important part is

.each(function(i){ 
    var eval("hb"+i )= $(this).htmlbox({

I tried the eval.. but I don't like that idea and it don't work anyway... any ideas?

EDIT: I can't do var eval("hb"+i )= $(this) and if I go

eval("hb"+i )= $(this)

I just get "hb0 is not defined"

Hope that makes sense. Thank you for the help. Cheers -Jeremy

1 Answer 1

2

Having var there won't help much at all -- even if it worked, it'd put the variables out of any useful scope in this case.

Globals are actually usually members of window, so what you could do, if you're ok with globals, is something like

.each(function(i) { 
    window["hb"+i] = $(this).htmlbox({ /* your params */ }); 
});
Sign up to request clarification or add additional context in comments.

6 Comments

that seems to work.. didn't get it working as this is the error.. global_hb.jqhb_0.cmd is not a function [Break On This Error] global_hb.jqhb_0.cmd("bold"); which means it works but the plugin don't understand.. :/ tk for the help.. other ideas?
Are you actually doing anything with the variables you're making here? As in, trying to trigger stuff in the boxes?
it looks like the plugin does just that.. thou I'm not sure how.. if you look in the link to the demo you'll see 2 of them editors working.. but in the code it's two vars... one for each.. I'd do that but there are pages it'll change in number.. so .. ??? lol
ok.. so I switched to window["hb_test__"+i] = $(this).attr("id","hb_test__"+i).htmlbox({ }); and it seems to work now... I'm still not sure where the var comes in but what I needed to do was add the an id on the fly.. tk for the help.. window[] is how and either it's needed.. who cares lol...
window["example"] = "This is now pretty much a 'global'"; alert(example);
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.