View Full Version : Javascript Question
I'm experimenting with using LPS to provide a menu bar for a ColdFusion application. I'm having a hard time figuring out how to get the JavaScript working that will allow the menu items to call the appropriate pages.
Here is the code for my working ColdFusion/HTML version using the HTML BUTTON tag to launch the JS event:
<input type="button" value="View Stats" class="Button" onClick="javascript:location.href='ViewStats.cfm';return false;">
The above is working.
Here's my LPS menu bar code:
<canvas width="400" height="27">
<command id="cmd_viewStats" label="View Stats"
onselect="javascript:location.href='ViewStats.cfm';return false;" />
<menubar width="210" height="25" clickable="true">
<menu label="Homepage" hasbutton="true" width="125" height="25" />
<menu label="Enter Stats" hasbutton="true" width="125" height="25" />
<menu label="View Stats" hasbutton="true" width="125" height="25" command="cmd_viewStats" />
</menubar>
</canvas>
This does not work. I have tried a number of things including trying to use Window.Open and changing the command to onClick instead of onSelect (onSelect is what was in the example code).
I have not been able to get this to work and in my review of the documentation I have not found an answer.
Thanks!
antun
02-08-2003, 06:29 PM
Hey jds
The best way is to define commands:-
<!-- in the canvas -->
<command id="cmd_openwin" label="Get View Sats"
onselect="LzBrowser.loadURL( 'javascript:location.href=\'http://www.laszlosystems.com/\'' )"
key="['Alt','Enter']"/>
<!-- then in the menu -->
<menuitem label="Get View Stats"
command="cmd_openwin"/>
However, I can't see why you're doing the javascript:location.href='' business.
You could just do:
LzBrowser.loadURL( 'http://www.laszlosystems.com/' )
Take care,
Antun
Well, I'm now getting some interesting action!
Based on your suggestion, here's what I did:
<canvas width="400" height="27">
<command id="cmd_ManageStatData" label="Manage Stat Data"
onclick="LzBrowser.loadURL( 'http://localhost/statsapp/ManageStats.cfm' )" />
<menubar width="400" height="25" clickable="true">
<menu label="Manage Stat Data" hasbutton="true" width="125" height="25" command="cmd_ManageStatData" />
</menubar>
</canvas>
When I click on the menu button in my other file the page in the command tag loads, and loads, and loads until I comment out the code and refresh the browser.
I then tried running the LZX file itself. At first it spits out the following error message:
Compilation Warnings
basicMenu.lzx:5:92: attribute "onSelect" not allowed at this point; ignored
basicMenu.lzx:7:59: element "menubar" from namespace "http://www.laszlosystems.com/2003/01/lzx" not allowed in this context
Then right after the menubar loads--and without me clicking on anything--it loads the page (reference in the command tag), over and over.
At least it's doing something now :-)
Now what?
antun
02-08-2003, 11:19 PM
Hey jds
I think it may be because you're using the onclick event with the command tag. It should be onselect. You can't really "click" a command; it's just a sort of predefined method call, that can be tied to things like menus.
-Antun
Antun -
My apologies. I incorrectly pasted in the snippet with the "onclick" instead of the "onselect".
I just re-tested the following code:
<canvas width="400" height="27">
<command id="cmd_ManageStatData" label="Manage Stat Data"
onSelect="LzBrowser.loadURL( 'http://localhost/statsapp/ManageStats.cfm' )" />
<menubar width="400" height="25" clickable="true">
<menu label="Home" hasbutton="true" width="125" height="25" command="cmd_Home" />
<menu label="Enter Stat Data" hasbutton="true" width="125" height="25" command="cmd_EnterStatData" />
<menu label="Manage Stat Data" hasbutton="true" width="125" height="25" command="cmd_ManageStatData" />
<menu label="Create Stat" hasbutton="true" width="125" height="25" command="cmd_EditStat" />
<menu label="Edit Stat" hasbutton="true" width="125" height="25" command="cmd_CreateStat" />
</menubar>
</canvas>
When run as an LZX file is automatically loads the page with no triggering event.
When run in the ColdFusion/HTML page and clicked it loads the page over and over until I comment out the code and refresh.
-- john
antun
02-09-2003, 09:26 AM
Hey jds
I just tried a quick test, and it seems to be the capital s in "onSelect". Try changing it to a lowecase s.
<canvas width="400" height="27">
<command id="cmd_ManageStatData" label="Manage Stat Data"
onselect="LzBrowser.loadURL( 'http://www.laszlosystems.com/' )" />
<menubar width="400" height="25" clickable="true">
<menu label="Manage Stat Data" hasbutton="true" width="125" height="25" command="cmd_ManageStatData" />
</menubar>
</canvas>
All attributes in LZX are lowecase as far as I know. APIs can have some capitals in them. In short, it's how they're noted in the LZX reference:-
http://www.laszlosystems.com/developers/learn/documentation/lzxref/LzView.php#tag-attributes
Take care,
Antun
Antun -
OK. I ran that exact code. I ran it as a straight LZX file.
What happens is that the command fires automatically (without clicking anything) and then the pages continuously re-loads.
Any ideas?
- John
antun
02-09-2003, 10:37 AM
Hey jds
I don't get that though. It doesn't fire automatically for me:
http://www.laszlosystems.com/lps-dr/my-apps/antun/commands/commands.lzx
That's weird. Could you send me your browser/player/server details please?
Also, one other thing - I should have picked up on this earlier. The syntax should be:-
<menubar>
<menu>
<menuitem command="..." />
</menu>
</menubar>
Note it goes <menubar>; then <menu>; then <menuitem>. I've tested this here:-
http://www.laszlosystems.com/lps-dr/my-apps/antun/commands/commands_newnesting.lzx
Remember you can view the source of the above by adding ?lzt=source to URL. I also had to change the height of your canvas to accomodate the whole menu.
Let me know if this works for you.
Take care,
Antun
Antun -
Thanks! That worked. It must have been the <menubar>, <menu>, <menuitem> positioning.
Now...here's a wierd thing. I tested this by running your code (with label = test). Once that worked I edited the file to change the labels and add some more menu items.
However, when I run it I see the old version (the one with 'test').
I tried stopping and starting Tomcat, that did not work.
I added '?lzt=source' and the correct source code displays--but it is not running for some reason.
I also noticed that the Tomcat window displays "responding with NOT_MODIFIED."
How do I force the LZX to "re-compile."?
Thanks.
- John
antun
02-09-2003, 06:32 PM
Hey John
Touching the file should make the LPS recompile the app. However we have noticed a bug in the DR release that causes it to recompile every time - the opposite to what you're seeing.
If you add the querystring:
?lzt=clearcache&pwd=laszlo to the URL in the browser, that should clear the cache. Then it will recompile from scratch. However check in your browser that you're not seeing the browser's cached version. If it still happens, let me know.
Take care,
Antun
vBulletin® v3.8.4, Copyright ©2000-2012, Jelsoft Enterprises Ltd.