This topic is locked

Javascript alert not showing up

9/26/2006 5:45:08 PM
PHPRunner General questions
G
gawde author

Hello All,
I have an error message in both the Before Record added and Before Record updated events that uses a simple Javascript alert snippet to display the error. Unfortunately the message does not show. It is because it is sent to the browser before the first html tag built for that page. Can anyone tell me how to overcome this timing issue?
Am using vers 3.0 build 119. By the way, it's a bit early to ask, but is this scenario any different in 3.1?

J
Jane 9/27/2006

Greg,
JavaScript works fine in the events for all PHPRunner versions.

I recommend you to check your code, display the values of variables before javascript message.
Also you can post your event code here and I'll help to find what's wrong.

G
gawde author 9/27/2006

Hi Jane,
Just to clarify the issue, it's that the Javasript is not executing. The message inside the alert window is fine. The Glass Shape ID really is empty. Anyway, I am posting the BeforeAdd event code and a few lines from the browser View of the resolved code. In performing a couple test runs I also noticed that the first call "(.....already exist") to the Java alert works. The 2nd and 3rd do not. Very perplexing. Thanks for your help.
<script> alert('Glass Shape ID '' not found in Glass Shape table.'); </script><html>

<title>Product - Fluorescent</title>

<link REL="stylesheet" href="include/style.css" type="text/css">

<script language="javascript">

var checkObjects = new Array();

var errors = "";

var RequiredMsg = "";
=====================================================================
function BeforeAdd(&$values)

{
// Parameters:

// $values - Array object.

// Each field on the Add form represented as 'Field name'-'Field value' pair
//** Check if specific record exists ****

global $conn;

$strSQLExists = "select from _ProdFluorescent where ItemIDFluor = ".$values["ItemIDFluor"];

$rsExists = db_query($strSQLExists,$conn);

$data=db_fetch_array($rsExists);
if($data)

{

// if record exists do something

echo "<script> alert('Item # ".$data["ItemIDFluor"]." already exists.'); </script>";

return false;

}

$strSQLExists = "select
from _ItemImage where FigureNum = ".$values["FigureNum"];

$rsExists = db_query($strSQLExists,$conn);

$data=db_fetch_array($rsExists);
if($data)

{

$values["GlassID"] = "'".$data["GlassIDFig"]."'";

$values["BaseID"] = "'".$data["BaseIDFig"]."'";

$values["BaseID2"] = "'".$data["BaseIDFig2"]."'";

}

else

{

echo "<script> alert('Figure # ".$values["FigureNum"]." not found in Item Image table.'); </script>";

return false;

}
$strSQLExists = "select * from _GlassShape where GlassID = ".$values["GlassID"];

$rsExists = db_query($strSQLExists,$conn);

$data=db_fetch_array($rsExists);
if($data)

{

$values["GlassDiam"] = "'".$data["GlassDiam"]."'";

$values["GlassDiammm"] = "'".$data["GlassDiammm"]."'";

}

else

{

echo "<script> alert('Glass Shape ID ".$values["GlassID"]." not found in Glass Shape table.'); </script>";

return false;

}
return true;
// return true if you like to proceed with adding new record

// return false in other case
}

J
Jane 9/28/2006

Greg,
it seems that alert doesn't work because there are two single quotes in the alert message.

Try to replace single quotes with double quotes:

...

$strSQLExists = "select * from _GlassShape where GlassID = ".$values["GlassID"];

$rsExists = db_query($strSQLExists,$conn);

$data=db_fetch_array($rsExists);
if($data)

{

$values["GlassDiam"] = "'".$data["GlassDiam"]."'";

$values["GlassDiammm"] = "'".$data["GlassDiammm"]."'";

}

else

{

echo "<script> alert('Glass Shape ID ".str_replace("'","\"",$values["GlassID"])." not found in Glass Shape table.'); </script>";

return false;

}

...

G
gawde author 9/28/2006

Thanks Jane. That did the trick.