Page 1 of 1

Popup Window Problem

Posted: Wed Feb 11, 2004 3:53 pm
by crandym
I am trying to build a user error notification via. a popup window. I know that javascript can be used to create new windows, however most examples I've reviewed use some sort of "click" triggered mechanism to post the window. I'd like to popup a window with an error message to the user when the error occurs. For example, if the user does a file upload and inputs an invalid file type. In php code, when I determine the file type is invalid, I'd like to then popup a window with a corresponding error message.

thanx

crandym

Posted: Wed Feb 11, 2004 3:56 pm
by josh
on your jscript the link should be something like this:

<a href="javascripts:(void)" onclick="something()>click</a>

Something like that

What this is doing is onclick do something(then possibly a url here)

when php echos the <head> etc... make your body tag say <body onload="something()">



That should work

Posted: Wed Feb 11, 2004 4:04 pm
by crandym
Do you happen to have a more specific example for what php needs to echo to invoke or trigger the onclick action?

Posted: Wed Feb 11, 2004 4:05 pm
by Illusionist
he doesn't want it on a click, i think he laready knows how to do that... He is asking how to when theres an error...

The way i would do it would be the same way as an onClickevent for a link... except you could have the window open to a php page, and pass the error message through and have it display....

Code: Select all

&lt;script&gt;
function PopUpError(error) &#123;
javascript:window.open('popup.php?error=error', 'Error', 'width=300,height=200,menubar=0,toolbar=no,scrollbars=no')
&#125;

Code: Select all

//On Error:
?>PopUp($error);
<?php
//continue with code
I'm pretty sure that'll work... may need a little tweaking but thats the basic idea

Posted: Wed Feb 11, 2004 4:07 pm
by Illusionist
oh, and on error.php just something like:

Code: Select all

<?php
$error = $_GET['error'];

echo $error;

?>

Posted: Wed Feb 11, 2004 4:11 pm
by crandym
Great thanx. I'll give it a go.

Posted: Wed Feb 11, 2004 4:20 pm
by crandym
I wasn't able to get the

?>PopUp($error);
<?php

to invoke the javascript. Any ideas?

Posted: Wed Feb 11, 2004 4:22 pm
by DuFF
Based on the little snippet of javascript posted above it should probably be:

Code: Select all

<?php
if($error) //blah blah, do whatever you want to check for an error
{
?>
PopUpError($error);
<?php 
}
else
{
//other code...
}
?>

Posted: Wed Feb 11, 2004 4:35 pm
by crandym
maybe the problem is because I am trying to call this from a php file which does not contain any html tags. Similar to concept of trying to call this from a php function?

Does there have to be an html base set of tags in order for browser to recognize a javascript call?

heres wut u do

Posted: Wed Feb 11, 2004 5:07 pm
by josh
you need to use php to echo (""); the following on an error

<html><head><title>Untitled Document</title><script>function PopUpError(error) {
javascript:window.open('popup.php?error=error', 'Error', 'width=300,height=200,menubar=0,toolbar=no,scrollbars=no')
}
</head>
<body onload="popuperror($error)>
</body>
</html>


then if (error) {
echo all the above
}

//otherwise it keeps going

so on an error your php returns the html code for a page witha popup


is this waht your trying to do?

Posted: Wed Feb 11, 2004 6:01 pm
by crandym
I have a php function "ReportUserError" which I use to send various types of messages. This function is in a php file, which contains several functions but no html. I am simply trying to allow the ReportUserError function to post the error message in a popup form.

What is the best approach.

umm

Posted: Wed Feb 11, 2004 6:33 pm
by josh
well i wouldnt be sure but your javascript needs to go in the header section of a page so keep that in mine, does the error HAVE to go in a new popup window?

Posted: Thu Feb 12, 2004 8:06 am
by crandym
What would be the most appropropriate way to handle user communitations with respects to errors? Maybe this is the question I should have asked initially?