Results 1 to 4 of 4

Thread: How can I call a javascript function from a link on popit menu?

  1. #1
    Join Date
    May 2011
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default How can I call a javascript function from a link on popit menu?

    1) Script Title: Pop-it menu
    2) Script URL (on DD): http://www.dynamicdrive.com/dynamicindex1/popit.htm

    3) Describe problem:I have a java script function which allow me to open a popup window as given below,

    function openPopup(url, name, w, h) {
    var winl = (screen.width - w) / 2;
    var wint = (screen.height - h) / 2;
    winprops = 'height='+h+',width='+w+',top='+wint+',left='+winl;
    win = window.open(mypage, myname, winprops)
    }

    I need to call this function from a link on pop-it menu, my code to call the java script function from the link on pop-it menu as given below

    Code:
    $linkset[0] .="<a href=www.google.com> Show Linked Companies </a>";
    Code:
    $linkset[0] .="<a href=javascript:openPopup('company.php?Action=ShowLinkedCompany&companyId={$companyId}', 'LinkedCompany', 900, 600);> Show Linked Companies </a>";
    But with this type of link pop-it menu is not being generated.
    Is their any way I can do this?
    Last edited by jscheuer1; 05-26-2011 at 02:00 PM. Reason: format code

  2. #2
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    Code:
    $linkset[0] .= '<a href="company.php?Action=ShowLinkedCompany&companyId={$companyId}" target="LinkedCompany" onclick="openPopup(this.href, this.target, 900, 600); return false;"> Show Linked Companies </a>';
    One thing I'm not clear on though, what's:

    Code:
    {$companyId}
    Is that some sort of token that gets replaced server side? If so, and it does get replaced, it should work out.
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  3. #3
    Join Date
    May 2011
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Thanks a lot Jhon, for your reply...

    I did in different way for now, but in future i will definitely use your way so that I don't have to create multiple java script function to open a popup. I did it right now as given below

    1 - Create a new java script function as shown
    function PopupLinkCompany(compId){
    var left = (screen.width/2)-(800/2);
    var top = (screen.height/2)-(400/2);
    winprops = 'height=400,width=800,top='+top+',left='+left;
    url = 'company.php?Action=ShowLinkedCompany&companyId='+compId;

    var Win = window.open(url, 'LinkCompany', winprops );
    }

    2 - Change the link in pop-it as given below
    $linkset[0] .="<a href=javascript:PopupLinkCompany($companyId);> Show Linked Companies </a>";

    I notice that, I can call the JavaScript function with a single input parameter and the input parameter should not be in single quote.

    Anyway, thanks again for your reply...

  4. #4
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    Quote Originally Posted by patelekta View Post
    I notice that, I can call the JavaScript function with a single input parameter and the input parameter should not be in single quote.
    As in all coding languages, when there are nested quotes you only have the two types to work with single and double. Once your requirements go beyond that you have to either write it differently or start escaping one or more levels of the quotes.

    I can't see what $companyId is getting resolved to. But if it is a value encased in quotes, single quotes - as it pretty much would have to be in the code you are showing - assuming that code is literal, then you've just used up the two types of quotes. Anything around $companyId cannot also use single quotes unless they're escaped for $companyId.

    It's easier to figure out if one looks at the live page in the browser and uses the browser's 'view source'. Then one can see how the server side tokens are being resolved and if anything needs to be escaped - assuming one knows proper quoting syntax for javascript.
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •