PDA

View Full Version : LBGW run function onload of window



burnside
12-05-2009, 05:55 PM
Hi,

am having trouble getting the function below to run onload of a page inside a LBGW window

at bottom of window
<script language="JavaScript">
toggleSet(document.forms[0].x_siteid[<%=cint(session("siteid")-1)%>]);
</script>

have tried
<script language="JavaScript">
toggleSet(document.forms["formname"].x_siteid[<%=cint(session("siteid")-1)%>]);
</script>

in "parent" page
<script type="text/javascript">
function toggleSet(rad) {
var type = rad.value;
var list=document.getElementsByTagName('div')
for(var k=0,elm;elm=list[k];k++)
if(elm.className=='item')
elm.style.display = elm.id==type? 'inline':'';
}
</script>

should i try and run it within the lightbox.js script?

djr33
12-06-2009, 02:33 AM
What is the <%....%> code? Is that ASP?
With two (or more) languages mixed, please explain how they work together and which one is the problem (if you know).

jscheuer1
12-06-2009, 08:45 AM
The mixture of languages can be confusing. But if we assume that the asp or asp-like part is OK and is being parsed as expected by the server, it would probably output an integer. So you would have something like:


toggleSet(document.forms[0].x_siteid[3]);

But, from what you say it appears that the toggleSet function is on the parent page, and that this code is in an iframe of that parent page. So you would at least have to do:


parent.toggleSet(document.forms[0].x_siteid[3]);

Now, you've made no indication of which of these two pages that forms[0] is on. If it is on the parent page, you would also need to add:


parent.toggleSet(parent.document.forms[0].x_siteid[3]);

Additionally, this pretty much assumes that wherever the form is, that it has a property (possibly an element - an input, button or textarea, or perhaps just some assigned property) that can be addressed as x_siteid[#], where # is an integer.

Finally, for now, since session("siteid") must at least be a number or be a string that the server can type convert to a number (otherwise there would be an error on the server side), session("siteid") might still be out of range of what is expected as a possible property value for the x_siteid property of the form.

This last bit can be observed (what cint(session("siteid")-1) works out to be on a case by case basis), by viewing the served source code of the page that has this on it.

Firefox with the developer's extension for it added is good for that as it would allow you to view the iframe's page's source without having to load the page separately.

If you want more help:

Please post a link to the page on your site that contains the problematic code so we can check it out.

burnside
12-06-2009, 01:35 PM
hi - apologies the browser output for that line is now



toggleSet(document.forms["homesetup"].x_siteid[0]);


- changed forms[0] to forms["homesetup"] which is the name of the form in the LBGW window
- x_siteid is a radio button in the LBGW window
- if the LBGW page is run direct in the browser it runs fine (if i include the toggleSet function in the page)
- this is an intranet site so cant 'easily' give a demo

if i run



<script type="text/javascript">
alert('hello');
</script>


at the bottom of the LBGW window it doesnt run?

jscheuer1
12-06-2009, 04:25 PM
LBGW has only one method for importing pages to its 'window'. This is AJAX. AJAX imported content generally will not run scripts that are included. And the LBGW 'window' is not a true window, it is just a divsion to which the external markup is imported. You need something like:

http://www.dolem.com/lytebox/

or:

http://www.stickmanlabs.com/lightwindow/

I'm sure there are several others, that can optionally import the external page to an iframe. There may even be other lightbox type scripts that can import via AJAX while optionally running a script on the imported page. But perhaps not.

Then (if using an iframe 'box' from a script that can do that) if the form is on the page in the window, and the function is on the parent page:


parent.toggleSet(document.forms["homesetup"].x_siteid[0]);

should work. If not, you may always just use:


toggleSet(document.forms["homesetup"].x_siteid[0]);

and include the toggleSet function on the page in the iframe box.

If you do by chance come across a lightbox type script that can import via AJAX while optionally running a script on the imported page, you may then most likely be able to use:


toggleSet(document.forms["homesetup"].x_siteid[0]);

with toggleSet on the 'top' page.

burnside
12-06-2009, 10:36 PM
can you tell me if i can show a hidden div onload of a LBGW modal div?


popup
[/code]
<style>
div.item{display: none; padding: 8px;}
</style>
<form name="homesetup" id="homesetup">
<div id='1' class='item'>
<!--content-->
</div>

<div id='2' class='item'>
<!--content-->
</div>

<div id='3' class='item'>
<!--content-->
</div>
</form>
[/code]

jscheuer1
12-06-2009, 10:58 PM
As far as I can see, no. You might be able to hack something together for it. But the two other scripts I mentioned, if you use their iframe methods, you can do just about anything like that you might want.

burnside
12-07-2009, 09:13 AM
thanks v.much for all your help - fixed this by using ASP to set the initial display style depending on x_siteid [messy ;-)]



<%if cint(j) = cint(x_siteid) then
showdept = "style=""display: inline;"""
else
showdept = "style=""display: none;"""
end if%>

<style>
div.item{display: none; padding: 8px;}
</style>
<form name="homesetup" id="homesetup">
<div id='1' class='item' <%=showdept%>>
<!--content-->
</div>

<div id='2' class='item' <%=showdept%>>
<!--content-->
</div>

<div id='3' class='item' <%=showdept%>>
<!--content-->
</div>
</form>

jscheuer1
12-07-2009, 05:24 PM
From that server side code it looks like you want to either show all three divisions or none of them, right?

If so, you could do like:


<%if cint(j) = cint(x_siteid) then
showdept = "inline"
else
showdept = "none"
end if%>

<style>
div.item{display: <%=showdept%>; padding: 8px;}
</style>
<form name="homesetup" id="homesetup">
<div id='1' class='item'>
<!-- content -->
</div>

<div id='2' class='item'>
<!-- content -->
</div>

<div id='3' class='item'>
<!-- content -->
</div>
</form>

Also: The id attribute is technically not allowed to begin with a number. So you may want to change that. The native display value for a div is 'block', so you may want to use that in place of 'inline'. But 'inline' is fine if that is what you intend. Style sections belong in the head of the page. My asp is a bit rusty. In most languages you need a == for comparison.