Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
Old 03-03-2008, 10:27 AM PHP javascript popup
Sharon_leic's Avatar
Super Talker

Posts: 115
Name: Sharon
Location: Leicester, uk
Trades: 0
I placed this question in this php part as it might be more related to php if that makes sense


i have the below line

PHP Code:
echo "<a href='im/private.php?".$rnp['login']."'target=_new>"."<img src='siteimages/im.jpg' border='0' alt='Private message'></a><br>"
that nicely brings up a new window to private message someone in.

however i need the new popup to be a set size with scroll turned of and set dimentions, say 200x200

i know i can do it like this with javascript in html

<a href="javascript:windowHandle = window.open('private.php.html','Private message','width=200,height=200, location=yes'); windowHandle.focus()">Private</a>

but i can't work out how to use the script it in php without getting a parse error.

can anyone help me please?

Thanks

Shaz x
__________________
mysql_connect("localhost", "brain", "sharon") or die(mysql_error());
mysql error: brain doesn't exist!

Last edited by Sharon_leic; 03-03-2008 at 10:33 AM..
Sharon_leic is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 03-03-2008, 10:52 AM Re: PHP javascript popup
pealo86's Avatar
Super Spam Talker

Posts: 876
Name: Matt Pealing
Location: England, north west
Trades: 0
Any code other than PHP, [e.g. html or javascript] would be entered as a string in PHP, just like normal text.

Well I think it should work with Javascript anyway, Ive only just started to learn it so I havent had the chance to mix it with PHP.

But I think so long as you just include it in the string it should work!
__________________

Please login or register to view this content. Registration is FREE
pealo86 is offline
Reply With Quote
View Public Profile Visit pealo86's homepage!
 
Old 03-03-2008, 10:57 AM Re: PHP javascript popup
Sharon_leic's Avatar
Super Talker

Posts: 115
Name: Sharon
Location: Leicester, uk
Trades: 0
yeah javascript can be used in strings, i have used a fair bit of java in php on my site, its just this that refuses to work grrr
__________________
mysql_connect("localhost", "brain", "sharon") or die(mysql_error());
mysql error: brain doesn't exist!
Sharon_leic is offline
Reply With Quote
View Public Profile
 
Old 03-03-2008, 11:42 AM Re: PHP javascript popup
tripy's Avatar
Do not try this at home!

Posts: 3,621
Name: Thierry
Location: I'm the uber Spaminator !
Trades: 0
PHP Code:
echo <<<html

<script type="text/javascript">
function privateMsg(id){
  w=window.open('im/private.php?'+id,'winPrivateMsg','height=200,width=200')
}
</script>
<a href="privateMsg('
{$rnp['login']}')"><img src='siteimages/im.jpg' border='0' alt='Private message'></a><br> 
html; 
You can put the javascript function definition in another file (I even recommend you to).
Then, you simply call that javascript function in the href (or onclick) and you pass the value of your $rnp['login'] variable.

I've added single quotes around the output of the value, because if it's alphanumeric, then javascript will raise an error if it's not between signle or double quotes.
Maybe it's what happened to you before.
HTML Code:
href="function(35467);"  <!-- this is fine -->
href="function(going_34456);" <!-- but this is not -->
href="function('going_34456');" <!-- this is ok -->
__________________
Only a biker knows why a dog sticks his head out the window.
tripy is offline
Reply With Quote
View Public Profile Visit tripy's homepage!
 
Old 03-03-2008, 12:07 PM Re: PHP javascript popup
Sharon_leic's Avatar
Super Talker

Posts: 115
Name: Sharon
Location: Leicester, uk
Trades: 0
aha i can see what you are saying although that code you wrote won't work for me

hmmmm maybe another bit of javascript on the same page might be interfering with it
__________________
mysql_connect("localhost", "brain", "sharon") or die(mysql_error());
mysql error: brain doesn't exist!
Sharon_leic is offline
Reply With Quote
View Public Profile
 
Old 03-03-2008, 12:16 PM Re: PHP javascript popup
Sharon_leic's Avatar
Super Talker

Posts: 115
Name: Sharon
Location: Leicester, uk
Trades: 0
when your code isn't in it my script works fine then if i add your code i get an error on the line after your code

this is the line of code i have after your script.. and its telling me there is an error in it

echo "<a href='viewprofile.php?".$rnp['login']."' target='_top'>".$rnp['login']."</a>";



error i am getting..
""Parse error: parse error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in c:\wamp\www\friends.php on line 41""
__________________
mysql_connect("localhost", "brain", "sharon") or die(mysql_error());
mysql error: brain doesn't exist!

Last edited by Sharon_leic; 03-03-2008 at 12:17 PM..
Sharon_leic is offline
Reply With Quote
View Public Profile
 
Old 03-03-2008, 01:26 PM Re: PHP javascript popup
Sharon_leic's Avatar
Super Talker

Posts: 115
Name: Sharon
Location: Leicester, uk
Trades: 0
I got it now thanks, and now know why my original way wouldn't work..

I had forgotton to close something else hehe

hanks again trippy

Shaz x
__________________
mysql_connect("localhost", "brain", "sharon") or die(mysql_error());
mysql error: brain doesn't exist!
Sharon_leic is offline
Reply With Quote
View Public Profile
 
Old 03-03-2008, 01:48 PM Re: PHP javascript popup
tripy's Avatar
Do not try this at home!

Posts: 3,621
Name: Thierry
Location: I'm the uber Spaminator !
Trades: 0
no problems
__________________
Only a biker knows why a dog sticks his head out the window.
tripy is offline
Reply With Quote
View Public Profile Visit tripy's homepage!
 
Old 03-03-2008, 02:17 PM Re: PHP javascript popup
Sharon_leic's Avatar
Super Talker

Posts: 115
Name: Sharon
Location: Leicester, uk
Trades: 0
GRRRRRRRRRRRRRRRRR!

ok, this is my page cut down
Code:
<html>

<script type="text/javascript">
function private(id){
  w=window.open('im/private.php?'+id,'winPrivateMsg','height=340,width=337')
}
</script>

</html>


<?
$poo = "Sharon";


echo "<a href='javascript:private($poo)'><img src='siteimages/im.jpg' border='0' alt='Private message'></a><br>";
?>
when the image is clicked it returns the error ~ 'Sharon' is undefined ~

can you tell me how to call the function from within the php file with the right (varible) please

Thanks

Shaz x
__________________
mysql_connect("localhost", "brain", "sharon") or die(mysql_error());
mysql error: brain doesn't exist!
Sharon_leic is offline
Reply With Quote
View Public Profile
 
Old 03-03-2008, 03:08 PM Re: PHP javascript popup
tripy's Avatar
Do not try this at home!

Posts: 3,621
Name: Thierry
Location: I'm the uber Spaminator !
Trades: 0
You need to place single or double quotes if the parameter is alpha numeric:
PHP Code:
echo "<a href='javascript:private($poo)'><img src='siteimages/im.jpg' border='0' alt='Private message'></a><br>";

//should be
echo "<a href='javascript:private(\'$poo\')'><img src='siteimages/im.jpg' border='0' alt='Private message'></a><br>"
What you did is telling javascript that the variable was a return of a function named "Sharon()".
Putting quotes tells the javascript engine that "Sharon" is aliteral value, and not a reference to an javascript function or object.
__________________
Only a biker knows why a dog sticks his head out the window.

Last edited by tripy; 03-03-2008 at 03:10 PM..
tripy is offline
Reply With Quote
View Public Profile Visit tripy's homepage!
 
Old 03-03-2008, 03:16 PM Re: PHP javascript popup
Sharon_leic's Avatar
Super Talker

Posts: 115
Name: Sharon
Location: Leicester, uk
Trades: 0
Its now returning "error: invalid character" :-(

where "$poo" is, its there members name, it can only contain letters, numbers or underscore
__________________
mysql_connect("localhost", "brain", "sharon") or die(mysql_error());
mysql error: brain doesn't exist!
Sharon_leic is offline
Reply With Quote
View Public Profile
 
Old 03-03-2008, 03:17 PM Re: PHP javascript popup
Sharon_leic's Avatar
Super Talker

Posts: 115
Name: Sharon
Location: Leicester, uk
Trades: 0
got it got it! wooohoooooooooo hehe

this worked
Code:
echo "<a href='javascript:private(\"$poo\")'><img src='siteimages/im.jpg' border='0' alt='Private message'></a><br>";
thankyou so much for your help!
only took 2 days to do this bit hehe
__________________
mysql_connect("localhost", "brain", "sharon") or die(mysql_error());
mysql error: brain doesn't exist!
Sharon_leic is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to PHP javascript popup
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.41433 seconds with 12 queries