JavaScript and client side scripting.
Moderator: General Moderators
justravis
Forum Commoner
Posts: 53 Joined: Mon Dec 16, 2002 3:18 am
Location: San Diego, CA
Contact:
Post
by justravis » Fri Dec 20, 2002 4:33 am
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";
?>
Johnm
Forum Contributor
Posts: 344 Joined: Mon May 13, 2002 12:05 pm
Location: Michigan, USA
Contact:
Post
by Johnm » Fri Dec 20, 2002 7:27 am
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)
{
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);
}
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 » Sat Dec 21, 2002 5:10 am
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)
{
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);
}
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>
Johnm
Forum Contributor
Posts: 344 Joined: Mon May 13, 2002 12:05 pm
Location: Michigan, USA
Contact:
Post
by Johnm » Sat Dec 21, 2002 9:27 am
Try throwing an alert in the function to see exactly what is being passed to it.
Code: Select all
function authWindow(authid)
{
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");
}
If the alert box only says "Object" then try it like this:
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:
Post
by justravis » Sat Dec 21, 2002 12:09 pm
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.
Johnm
Forum Contributor
Posts: 344 Joined: Mon May 13, 2002 12:05 pm
Location: Michigan, USA
Contact:
Post
by Johnm » Sat Dec 21, 2002 12:15 pm
Glad I could help.
John M