?
Solved

PHP w/ java script

Posted on 2003-03-11
4
Medium Priority
?
233 Views
Last Modified: 2012-05-04
this is a snipset of the program.. I'm trying to make the jscript run.

$err[9]="Please fill up the Citizenship field";
$err[10]="Please fill up the Age field";
$err[11]="Please fill up the Weight field";

echo'<script language="javascript">';
echo 'alert("'.$err[$ctr].'")';<--- having problem's with this part>
?>
history.go(-1)
</script>
<?

nevermind.but if can give an alternative i'll gladly give the 5.
0
Comment
Question by:mazkot
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
4 Comments
 
LVL 11

Expert Comment

by:jausions
ID: 8116374
Hi,

Try the following (Basically, add line returns.)

Regards,

 -Philippe

----------------------------------------------

$err[9]='Please fill up the Citizenship field';
$err[10]='Please fill up the Age field';
$err[11]='Please fill up the Weight field';

echo "<script language=\"javascript\" type=\"text/javascript\">\r\n<!--\r\n";
echo 'alert("' . addslashes($err[$ctr]) . '")';
?>
history.go(-1)
// -->
</script>
<?
0
 
LVL 11

Expert Comment

by:jausions
ID: 8116382
Also, add the ";" at the end  of the JavaScript lines.
0
 
LVL 15

Expert Comment

by:VGR
ID: 8118817
basically, you don't change anything from what he wrote.
You added the <!-- hide from impared browsers
you addslashes() strings that do not contain to-be-escaped characters...

First for the jscript to run it has to be in the BODY part of the HTML page.
This stated, you forgot the ending semicolon and add \r\n after each line in your script, like this :
echo 'alert("'.$err[$ctr].'");\r\n';

Please also copy-paste here the HTML code generated so that we may check if $err[$ctr] has received a proper value.

regards,
0
 
LVL 11

Accepted Solution

by:
jausions earned 400 total points
ID: 8118989
Ok, here it is...

Key thing here is the line returns, otherwise web browser won't be happy...

I made it clearer on this version... (Note: echo() function doesn't output a line return.)

addslashes() is mandatory to avoid corrupting your JavaScript (Who knows if a quote or double-quote are in the 0-8 $err value...)

----------------------------------------------
<?php

...

$err[9]='Please fill up the Citizenship field';
$err[10]='Please fill up the Age field';
$err[11]='Please fill up the Weight field';

?>
<script language="javascript" type="text/javascript">
<!--
alert("<?php echo addslashes($err[$ctr]) ?>");
history.go(-1);
// -->
</script>
<?php

...
0

Featured Post

WordPress Tutorial 3: Plugins, Themes, and Widgets

The three most common changes you will make to your website involve the look (themes), the functionality (plugins), and modular elements (widgets).

In this article we will briefly define each again, and give you directions on how to install them.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I imagine that there are some, like me, who require a way of getting currency exchange rates for implementation in web project from time to time, so I thought I would share a solution that I have developed for this purpose. It turns out that Yaho…
There are times when I have encountered the need to decompress a response from a PHP request. This is how it's done, but you must have control of the request and you can set the Accept-Encoding header.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …
Suggested Courses

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question