window.open

JavaScript and client side scripting.

Moderator: General Moderators

Post Reply
justravis
Forum Commoner
Posts: 53
Joined: Mon Dec 16, 2002 3:18 am
Location: San Diego, CA
Contact:

window.open

Post by justravis »

I need to write a author popup for my article pg. The author id needs to be passed to the pg popping up.

It's not even popping up. Any ideas why? Thank you.

Function:

Code: Select all

<script language = "javascript">
        <!--

                function authorWindow(authid)
                {
                        window.open("author.php?authid=" + authid, "width=200, height=150,directories=0,location=0, menubar=0, resizable=0, scrollbars=0, status=0, toolbar=no");
                        //alert(authid);
                }
        //-->
</script>
Function Call:

Code: Select all

<?php
echo "<a href="#" onClick='authorWindow($authid)'><b>$name</b></a><br>\n";
?>
User avatar
Johnm
Forum Contributor
Posts: 344
Joined: Mon May 13, 2002 12:05 pm
Location: Michigan, USA
Contact:

Post by Johnm »

justravis,
Is the function call within form tags? Is it a valid html input on the page or is it strictly a php var? If it is not a valid form element you will have to make it one.

Code: Select all

<input type="hidden" name="authid" value="<? echo $authid ?>
Then you can refer to it as a form element:

Code: Select all

<?php 
echo "<a href="#" onClick='authorWindow(this.form.authid)'><b>$name</b></a><br>\n"; 
?>
Then in the function:

Code: Select all

function authorWindow(authid) 
    &#123; 
         window.open("author.php?authid=" + authid.value, "auth_win", "width=200, height=150,directories=0,location=0, menubar=0, resizable=0, scrollbars=0, status=0, toolbar=no"); 
          //alert(authid.value); 
      &#125;
I added a name "auth_win" which is the name of the new window the rest is pretty self explanatory.

John M
justravis
Forum Commoner
Posts: 53
Joined: Mon Dec 16, 2002 3:18 am
Location: San Diego, CA
Contact:

Post by justravis »

Thanks for the help.

I'm getting the popup, but the function is not passing the variable to the next pg.

The url looks like this:
author.php?authid=undefined

Here is what I have now:

New Function:

Code: Select all

function authWindow(authid)
&#123;
window.open("author.php?authid=" + authid.value, "author_window", "width=200, height=150, directories=0, location=1, menubar=0, resizable=0, scrollbars=0, status=0, toolbar=no");
                        //alert(authid.value);
&#125;
Portion I converted to Form:

Code: Select all

<form name=author>

<input type=hidden name=authid1 value=1>
<a href="#" onClick='authWindow(author.authid1.value)'>
<b>Author Name1</b></a><br>

<input type=hidden name=authid2 value=3>
<a href="#" onClick='authWindow(author.authid2.value)'>
<b>Author Name2</b></a><br>

</form>
User avatar
Johnm
Forum Contributor
Posts: 344
Joined: Mon May 13, 2002 12:05 pm
Location: Michigan, USA
Contact:

Post by Johnm »

Try throwing an alert in the function to see exactly what is being passed to it.

Code: Select all

function authWindow(authid) 
&#123; 
alert(authid.value); 
window.open("author.php?authid=" +     authid.value, "author_window", "width=200, height=150, directories=0, location=1, menubar=0, resizable=0, scrollbars=0, status=0, toolbar=no"); 
&#125;
If the alert box only says "Object" then try it like this:

Code: Select all

alert(authid);
and see if you need only pass the new window authid rather than authid.value.

Let me know how it works out.


John M
justravis
Forum Commoner
Posts: 53
Joined: Mon Dec 16, 2002 3:18 am
Location: San Diego, CA
Contact:

javascript seems inconsistent

Post by justravis »

Is it just me? Javascript seems very inconsistent.

Last night, I updated the function calls to look like what you posted, but I forgot to update the function. Originally, there was not a ".value" in the function. The window would not even pop up, but now it works. WIERD!!!

I was using alert() to test. That was the only reason it was in the function. At one point, it was aleting "Undefined."

THANK.
User avatar
Johnm
Forum Contributor
Posts: 344
Joined: Mon May 13, 2002 12:05 pm
Location: Michigan, USA
Contact:

Post by Johnm »

Glad I could help.


John M
Post Reply