Page 1 of 1

Pulldown Menu questions

Posted: Wed Sep 23, 2015 10:31 am
by randyh
I have a screen with a horizontal pulldown menu bar defined across the top. When I click on the menu element I would like it to open a new web page and display a PDF document to the user. I've created a javascript function in 2 places, onoptionclick (menuoptions) and onclick (events). I used the get() to retrieve the value of Menu2 but it does not execute it. If I just put the window.open statement in it works fine, but I will have different PDF documents that I'd like to display.

Here is the my javascript
function myForm(){
var f = get("Menu2");
if (f === "F200"){
window.open("http://intra.smtl.com:8500/pdf/f200.pdf");
} else {
pui.click();
}
}

myForm();

Re: Pulldown Menu questions

Posted: Wed Sep 23, 2015 6:38 pm
by Scott Klement
The onoptionclick event should be passing the menu item (that was clicked) to your function. See the example, here:
http://www.profoundlogic.com/docs/pages ... Id=5275826

Instead of using get() to try to get the value, can you try just using the value that's passed to your onoptionclick event?

Re: Pulldown Menu questions

Posted: Thu Sep 24, 2015 10:17 am
by randyh
I very new to javascript, I've added the onoptionclick as suggested and it still did not work for me. When I hard coded the value "F200" in the javascript function, it worked, I'm do not understand how the value of this element is passed into the javascript function as noted below?

function processMenuOption(value) {
switch(value) {
case "F200":
// code to process menu option 01 would go here
window.open("http://intra.smtl.com:8500/pdf/f200.pdf");
break;
}
}

processMenuOption("F200"); (<---how do I place the choice value here)

Re: Pulldown Menu questions

Posted: Thu Sep 24, 2015 12:20 pm
by Scott Klement
Not sure I know how you're coding this. is "processMenuOption" coded in a separate JS file and you call it from the "onoptionclick" property? Or are you coding this directly in the property? Or what?

Profound UI will have variables named 'value' and 'text' that are already set prior to running your routine. So, since the code you posted here is rather simple (but, of course, I don't know if there is more that you didn't post) it might be easy enough to just code it directly in the onoptionclick rather than defining a function.

So, if you did it that way, you could simply put this (without the 'function' definition) in your onoptionclick:

Code: Select all

switch(value) {
case "F200":
   // code to process menu option 01 would go here
   window.open("http://intra.smtl.com:8500/pdf/f200.pdf");
   break;
}
Or, if the PDF name always matches the "choice values" of the selected item, then you could simplify it to this:

Code: Select all

// since "value" wil contain "F200", this will launch F200.pdf
window.open("http://intra.smtl.com:8500/pdf/"+ value + ".pdf");
Also, if "intra.smtl.com:8500" is the same server instance that you are running Profound UI on, I would leave that out of the URL. That way, if you ever change your server name or try to run this on a different server, you won't have to change your code. In that case, it'd look like this:

Code: Select all

// since "value" wil contain "F200", this will launch F200.pdf
// this is a "relative" URL, it will launch documents from the server instance that my display is served from.
window.open("/pdf/"+ value + ".pdf");
If your code is more complex and would benefit from putting it in a separate .js file, then you would want to keep the "function" parts the way you had them before and call it like this...

Code: Select all

processMenuOption(value);
... this would make debugging a lot easier, so it makes a lot of sense for a more complex routine. The earlier suggestions are only given because your routine seems so simple that it may not be worth the extra effort of putting it in a separate file -- but it's up to you.

Does that help?

Re: Pulldown Menu questions

Posted: Fri Sep 25, 2015 4:51 pm
by randyh
Scott

Now that I know that the function definition is not needed, that awesome and I understand how it works.

Re: Pulldown Menu questions

Posted: Fri Sep 25, 2015 5:40 pm
by Scott Klement
Great!

Yeah, I think that example in the documentation is a bit confusing. The intention was that this tells you what to set the widget's property to:
widgetproperty.png
widgetproperty.png (2.69 KiB) Viewed 531 times
And then the JS function would be a function called from a separate .js file, which it shows in the docs like this:
functiondef.png
functiondef.png (11.96 KiB) Viewed 531 times
So that is how that example works -- but it is confusing because it doesn't explain that very well. I'll go in there and see if I can make it clearer.

Re: Pulldown Menu questions

Posted: Fri Sep 25, 2015 5:49 pm
by Scott Klement
Okay, I updated the docs a little bit. I put a screenshot of the widget property (instead of just text like was there before) and added some words to clarify things a litle bit. Hopefully that makes the docs easier to understand.