Jump to content

[SOLVED] Simple javascript function question


Jason28

Recommended Posts

Hello, I would like to pass variables into an existing function.  Here is a popup function that I like using:

 

function openpopup(popurl)
{
   winpops=window.open(popurl,"","width=650,height=493,scrollbars=yes")
}

 

and it is called up by using a link such as:

 

<a href="terms.php" onclick="openpopup(this.href);return false">Terms</a

 

My question is that can you give me a working example so that I can pass the height, width, and scrollbars vars from the link into the function?  That way I can just pass those vars from different urls so I can have different size popups for each link.  Thanks!

Link to comment
Share on other sites

Sorry an update, I want to use this other function instead of the first function I posted:

 

function openWin()

{

    win = window.open("test.php?action=view_users", "Window",

    "width=810,height=600,scrollbars=yes");

}

 

Please let me know how to pass vars from a webpage into this function.  Thanks!

Link to comment
Share on other sites

function openWin(width, height, scroll){ //scroll = yes/no
    win = window.open("test.php?action=view_users", "Window", "width="+width+",height="+height+",scrollbars="+scroll);
}

 

 

<a href="terms.php" onclick="openWin("600", "400", "yes");return false">Terms</a

 

(are you sure you don't want the url for the popup to be dynamic? in the "new" function you posted it will not be given to the function by your link)

Link to comment
Share on other sites

Thanks bud I got it to work :D  Sorry one last simple question.  One one link I used:

 

 onClick="javascript:goHide('div1'); go('div2')"

 

However I assume there is a better way to write that instead of calling the same function twice?  If not no big deal. Thanks!

Link to comment
Share on other sites

There will be hardly any better way, except if it happens often that you want to hide more div's at the same thime -> than you could put all wanted divs in an array and give the array to your function. But also then the function does everything again for every div. So it will not be a big deal :)

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.