Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > PHP/MySQL > PHP How-To
Password Reminder
Register
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
PHP How-To Post your "How do I do this with PHP?" questions here.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the PHP How-To section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developersí questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Display Modes
  #1 (permalink)  
Old January 23rd, 2005, 05:42 AM
Authorized User
 
Join Date: Jan 2005
Location: , , .
Posts: 32
Thanks: 0
Thanked 0 Times in 0 Posts
Default How to embed javascript in php code

Hi,

i was wondering if anyone can help. i am trying to get a simple alert msg box to appear when a user types something wrong: i have tried the following code:

if (!$FNameFrm)
{
echo "<script type = "text/javascript">\n";
echo "alert('You must enter first name');\n";
echo "</script>";
exit;
}

if this cant be done can anyone tell me how i get this msg to display on same page instead of oprn another page with just this message on it.

echo "You have not entered all details.<br>Please go back and try again.";



Thanks in advanced

Scoobie

Reply With Quote
  #2 (permalink)  
Old January 24th, 2005, 03:38 PM
Friend of Wrox
 
Join Date: Nov 2003
Location: , , .
Posts: 1,285
Thanks: 0
Thanked 1 Time in 1 Post
Default

This:

if (!$FNameFrm)
{
echo "<script type = "text/javascript">\n";
echo "alert('You must enter first name');\n";
echo "</script>";
exit;
}

Should be:

if (!$FNameFrm)
{
echo "<script type='text/javascript'>\n";
echo "alert('You must enter first name');\n";
echo "</script>";
exit;
}

Note the change of quotes.

hth,

-Snib - http://www.snibworks.com
Where will you be in 100 years?
Reply With Quote
  #3 (permalink)  
Old January 24th, 2005, 06:23 PM
Authorized User
 
Join Date: Jan 2005
Location: , , .
Posts: 32
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks very much Snib.
that worked.

i have another problem. the alert box comes up but when i click ok it gives me a blank white screen. how do i get it to return to the page so they can re-enter their name when they click ok on alert box.

Scoobie

Reply With Quote
  #4 (permalink)  
Old December 12th, 2006, 09:09 PM
Authorized User
Points: 209, Level: 4
Points: 209, Level: 4 Points: 209, Level: 4 Points: 209, Level: 4
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Apr 2005
Location: , , .
Posts: 49
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi, i'm kinda new to php. how would i embed my adsense javascript code which looks like this:

<script type="text/javascript"><!--
google_ad_client = "pub-7445480245484218";
google_ad_width = 728;
google_ad_height = 90;
google_ad_format = "728x90_as";
google_ad_type = "text_image";
google_ad_channel = "";
google_color_border = "FFFFFF";
google_color_bg = "FFFFFF";
google_color_link = "0000FF";
google_color_text = "000000";
google_color_url = "008000";
//--></script>
<script type="text/javascript"
  src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script>

into a php file. I have a script that essentially shows a sitemap of my site.

For reference, it can be seen at:
it can be seen at http;//www.duhsoft.com/physics

Reply With Quote
  #5 (permalink)  
Old December 13th, 2006, 10:51 PM
Friend of Wrox
 
Join Date: Oct 2003
Location: colombo, WP, Sri Lanka.
Posts: 482
Thanks: 0
Thanked 2 Times in 2 Posts
Send a message via MSN to surendran Send a message via Yahoo to surendran
Default

scoobie,
add this code..
if (!$FNameFrm)
{
echo "<script type='text/javascript'>\n";
echo "alert('You must enter first name');\n";
echo "return false;\n";
echo "</script>";
}


surendran
(Anything is Possible)
http://ssuren.spaces.msn.com
Reply With Quote
  #6 (permalink)  
Old December 13th, 2006, 10:53 PM
Friend of Wrox
 
Join Date: Oct 2003
Location: colombo, WP, Sri Lanka.
Posts: 482
Thanks: 0
Thanked 2 Times in 2 Posts
Send a message via MSN to surendran Send a message via Yahoo to surendran
Default

jilly,
Add this script in to one page call ads.php, and call this to your main page like
<?php
include("ads.php");
?>

surendran
(Anything is Possible)
http://ssuren.spaces.msn.com
Reply With Quote
  #7 (permalink)  
Old November 11th, 2007, 01:02 PM
Registered User
 
Join Date: Nov 2007
Location: , , .
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi,
I have this php script which has javascript embedded in it. I want to display an image and i have a javascript to show the image coordinates when the user moves the cursor.The image does not get displayed when i use this javascript. Any suggestions from your side would be of great help to me.
Thanks in advance.
Amrita
Reply With Quote
  #8 (permalink)  
Old November 11th, 2007, 01:07 PM
Registered User
 
Join Date: Nov 2007
Location: , , .
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi,
Sorry I forot to attached the code in my previous post.
Thank you
Amrita.



<head>
    <title>Untitled</title>


<script language="JavaScript">

function point_it(event){

    pos_x = event.offsetX?(event.offsetX):event.pageX-document.getElementById("pointer_div").offsetLeft;

    pos_y = event.offsetY?(event.offsetY):event.pageY-document.getElementById("pointer_div").offsetTop;

    document.getElementById("cross").style.left = (pos_x-1) ;

    document.getElementById("cross").style.top = (pos_y-15) ;

    document.getElementById("cross").style.visibility = "visible" ;

    document.pointform.form_x.value = pos_x;

    document.pointform.form_y.value = pos_y;

}

</script>
</head>



 <?if(1==1){?>

                 <legend>Image View</legend>

<form name="pointform" method="post">

<div id="pointer_div" onclick="point_it(event)" style = "background-image:url('vImage.jpg');width:500px;height:333px;" >

<img src=<img src="images/n.jpg" id="cross" style="position:relative;visibility:hidden;z-index:2;"></div>

You pointed on x = <input type="text" name="form_x" size="4" /> - y = <input type="text" name="form_y" size="4" />

</form>


             <?=$folder.$vThumbImage;?>
Reply With Quote
  #9 (permalink)  
Old November 28th, 2007, 01:11 PM
Registered User
 
Join Date: Nov 2007
Location: , , .
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Amrita12

this:
if(1==1){

must be closed with a bracket }
somewhere
or don't use this <?if(1==1){?> at all

 and :
<img src=<img src="images/n.jpg" id="cross"

must be
<img src="images/n.jpg" id="cross"

i think


---------------
Canon PowerShot SD1000
http://astore.amazon.com/powershot08-20

Reply With Quote
Reply


Thread Tools
Display Modes

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 Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
php and javascript rakesh nair Pro PHP 1 March 21st, 2007 05:58 PM
adding php code in javascript chayanvinayak Javascript How-To 2 December 18th, 2006 01:33 AM
Embed XHTML code Markus XSLT 2 January 1st, 2006 12:41 PM
embed image in php html email cullancrothers PHP How-To 12 September 16th, 2005 08:09 AM
PHP and Javascript davidhayter Beginning PHP 5 May 6th, 2005 05:33 AM



All times are GMT -4. The time now is 01:48 AM.


Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.