473,836 Members | 1,457 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

calling a javascript alert from php

hi i want to be able to trigger a javascript style popup alert in php
(i want a message displayed on the actual page) is this possible?

Jul 13 '06 #1
13 18691
monomaniac21 wrote:
hi i want to be able to trigger a javascript style popup alert in php
(i want a message displayed on the actual page) is this possible?

I'll take this one ... all I usually do here is ask questions.

The answer to your question is No. Php is run on the *server before* the
page is displayed. Therefore, Php cannot popup an alert like JavaScript
(which runs on the *client computer after* the page is loaded).

That said; if you want to implement a two step procedure like

(1) Delete this file.
(2) Are you Sure (Y or N)?

You can do that with Php, but clicking on (1) must create a request to
the server to display a new page with (2) as a form or hyperlinks.
Clicking on Y or N must return to the server again in able to perform
the action.

--
*************** **************
Chuck Anderson • Boulder, CO
http://www.CycleTourist.com
Everyone's journey should be different,
so that we all are enriched
in new and endless ways
*************** **************
Jul 13 '06 #2
Chuck Anderson wrote:
monomaniac21 wrote:
>hi i want to be able to trigger a javascript style popup alert in php
(i want a message displayed on the actual page) is this possible?

I'll take this one ... all I usually do here is ask questions.

The answer to your question is No. Php is run on the *server before* the
page is displayed. Therefore, Php cannot popup an alert like JavaScript
(which runs on the *client computer after* the page is loaded).

That said; if you want to implement a two step procedure like

(1) Delete this file.
(2) Are you Sure (Y or N)?

You can do that with Php, but clicking on (1) must create a request to
the server to display a new page with (2) as a form or hyperlinks.
Clicking on Y or N must return to the server again in able to perform
the action.
or you can have the php spit out the javascript as part of the page and
trigger it from the onclick= in the submit.

-david-

Jul 13 '06 #3
David Haynes wrote:
Chuck Anderson wrote:
>monomaniac21 wrote:
>>hi i want to be able to trigger a javascript style popup alert in php
(i want a message displayed on the actual page) is this possible?
I'll take this one ... all I usually do here is ask questions.

The answer to your question is No. Php is run on the *server before* the
page is displayed. Therefore, Php cannot popup an alert like JavaScript
(which runs on the *client computer after* the page is loaded).

That said; if you want to implement a two step procedure like

(1) Delete this file.
(2) Are you Sure (Y or N)?

You can do that with Php, but clicking on (1) must create a request to
the server to display a new page with (2) as a form or hyperlinks.
Clicking on Y or N must return to the server again in able to perform
the action.

or you can have the php spit out the javascript as part of the page and
trigger it from the onclick= in the submit.

-david-
But that's not "triggered in Php" and is simply JavaScript.

--
*************** **************
Chuck Anderson • Boulder, CO
http://www.CycleTourist.com
Everyone's journey should be different,
so that we all are enriched
in new and endless ways
*************** **************
Jul 13 '06 #4
Chuck Anderson wrote:
David Haynes wrote:
>Chuck Anderson wrote:
>>monomaniac2 1 wrote:

hi i want to be able to trigger a javascript style popup alert in php
(i want a message displayed on the actual page) is this possible?
I'll take this one ... all I usually do here is ask questions.

The answer to your question is No. Php is run on the *server before*
the page is displayed. Therefore, Php cannot popup an alert like
JavaScript (which runs on the *client computer after* the page is
loaded).

That said; if you want to implement a two step procedure like

(1) Delete this file.
(2) Are you Sure (Y or N)?

You can do that with Php, but clicking on (1) must create a request
to the server to display a new page with (2) as a form or hyperlinks.
Clicking on Y or N must return to the server again in able to perform
the action.

or you can have the php spit out the javascript as part of the page and
trigger it from the onclick= in the submit.

-david-
But that's not "triggered in Php" and is simply JavaScript.
Yes, but you had already provided "you can't get there from here"
answer. Sometimes it pays to offer alternatives rather than just to
answer the question someone has asked.

-david-

Jul 13 '06 #5
"monomaniac 21" <mc******@googl email.comwrote in message
news:11******** **************@ 35g2000cwc.goog legroups.com...
hi i want to be able to trigger a javascript style popup alert in php
(i want a message displayed on the actual page) is this possible?
Not by PHP alone but have a look at http://www.xajaxproject.org/ to things
like this...

Norm
Jul 13 '06 #6
David Haynes wrote:
Chuck Anderson wrote:
>David Haynes wrote:
>>Chuck Anderson wrote:

monomaniac 21 wrote:

hi i want to be able to trigger a javascript style popup alert in php
(i want a message displayed on the actual page) is this possible?
>
>
I'll take this one ... all I usually do here is ask questions.

The answer to your question is No. Php is run on the *server before*
the page is displayed. Therefore, Php cannot popup an alert like
JavaScript (which runs on the *client computer after* the page is
loaded).

That said; if you want to implement a two step procedure like

(1) Delete this file.
(2) Are you Sure (Y or N)?

You can do that with Php, but clicking on (1) must create a request
to the server to display a new page with (2) as a form or
hyperlinks . Clicking on Y or N must return to the server again in
able to perform the action.
or you can have the php spit out the javascript as part of the page and
trigger it from the onclick= in the submit.

-david-
But that's not "triggered in Php" and is simply JavaScript.
Yes, but you had already provided "you can't get there from here"
answer. Sometimes it pays to offer alternatives rather than just to
answer the question someone has asked.

-david-
I am following this thread because I am trying to do the same thing.
Problem is I do not know php\javascript all that well. I had posed my
code to this newsgroup but received no answer. So I do not know if I can
do what I am trying to do or I am just so far off that it does not
warent an answer. This is what I have so far. I can not get to work and
have comment out what I am trying:

//
// Handle the data coming back
echo '<FORM NAME=author method=post action='.$_SERV ER['PHP_SELF'].'>';
//echo '<SELECT NAME=author_pk SIZE=20 COLS=20 ONCHANGE='.$_PO ST[id].'>';
//echo '<SELECT NAME=author_pk SIZE=20 COLS=20 ONCHANGE=getPK( )>';
echo '<SELECT NAME=author_pk SIZE=20 COLS=20>';

while ($rows = mysql_fetch_obj ect($result)) {
echo '<OPTION VALUE='.$rows->id.'>'.
$rows->TITLE.' '.
$rows->lastname.', '.
$rows->firstname.
$rows->middlename.
$rows->SUFFIX.
'</OPTION>';
}
echo '</SELECT>';
echo '</FORM>';
//echo '<script language=Javasc ript>';
//echo 'function getPK() {';
//echo
"document.autho r.author_pk.opt ions[document.author .author_pk.sele ctedIndex].value
";
//echo '}';
//echo "</script>";

--

Thanks in Advance...
IchBin, Pocono Lake, Pa, USA http://weconsultants.phpnet.us
_______________ _______________ _______________ _______________ ______________

'If there is one, Knowledge is the "Fountain of Youth"'
-William E. Taylor, Regular Guy (1952-)
Jul 14 '06 #7
David Haynes wrote:
Chuck Anderson wrote:
>David Haynes wrote:
>>Chuck Anderson wrote:

monomaniac 21 wrote:

hi i want to be able to trigger a javascript style popup alert in php
(i want a message displayed on the actual page) is this possible?
>
>
I'll take this one ... all I usually do here is ask questions.

The answer to your question is No. Php is run on the *server before*
the page is displayed. Therefore, Php cannot popup an alert like
JavaScript (which runs on the *client computer after* the page is
loaded).

That said; if you want to implement a two step procedure like

(1) Delete this file.
(2) Are you Sure (Y or N)?

You can do that with Php, but clicking on (1) must create a request
to the server to display a new page with (2) as a form or
hyperlinks . Clicking on Y or N must return to the server again in
able to perform the action.
or you can have the php spit out the javascript as part of the page and
trigger it from the onclick= in the submit.

-david-
But that's not "triggered in Php" and is simply JavaScript.
Yes, but you had already provided "you can't get there from here"
answer. Sometimes it pays to offer alternatives rather than just to
answer the question someone has asked.

-david-
I am following this thread because I am trying to do something simular.
That is pass value back to php on a select ONCHANGE=. Problem is I do
not know php\javascript all that well. I had posted my code to this
newsgroup but received no answer. So I do not know if I can do what I am
trying to do or I am just so far off that it does not warent an answer.
This is what I have so far. I can not get to work and have comment out
what I am trying:

//
// Handle the data coming back
echo '<FORM NAME=author method=post action='.$_SERV ER['PHP_SELF'].'>';
//echo '<SELECT NAME=author_pk SIZE=20 COLS=20 ONCHANGE='.$_PO ST[id].'>';
//echo '<SELECT NAME=author_pk SIZE=20 COLS=20 ONCHANGE=getPK( )>';
echo '<SELECT NAME=author_pk SIZE=20 COLS=20>';

while ($rows = mysql_fetch_obj ect($result)) {
echo '<OPTION VALUE='.$rows->id.'>'.
$rows->TITLE.' '.
$rows->lastname.', '.
$rows->firstname.
$rows->middlename.
$rows->SUFFIX.
'</OPTION>';
}
echo '</SELECT>';
echo '</FORM>';
//echo '<script language=Javasc ript>';
//echo 'function getPK() {';
//echo
"document.autho r.author_pk.opt ions[document.author .author_pk.sele ctedIndex].value
";
//echo '}';
//echo "</script>";
--

Thanks in Advance...
IchBin, Pocono Lake, Pa, USA http://weconsultants.phpnet.us
_______________ _______________ _______________ _______________ ______________

'If there is one, Knowledge is the "Fountain of Youth"'
-William E. Taylor, Regular Guy (1952-)
Jul 14 '06 #8
Rik
IchBin wrote:
I am following this thread because I am trying to do something
simular.
That is pass value back to php on a select ONCHANGE=. Problem is I do
not know php\javascript all that well. I had posted my code to this
newsgroup but received no answer. So I do not know if I can do what I
am
trying to do or I am just so far off that it does not warent an
answer.
javascript/HTML is just plain text to PHP, you're better of asking an a
javascript group how you should accomplish what you're trying, get the
javascript code for that, and then build it in PHP.

What is it exactly you're trying to accomplish, because I can't make it out
from the following code?
(and BTW: <selectdoesn' t have a cols attribute...).
This is what I have so far. I can not get to work and have comment out
what I am trying:

//
// Handle the data coming back
echo '<FORM NAME=author method=post action='.$_SERV ER['PHP_SELF'].'>';
//echo '<SELECT NAME=author_pk SIZE=20 COLS=20
ONCHANGE='.$_PO ST[id].'>'; //echo '<SELECT NAME=author_pk SIZE=20
COLS=20 ONCHANGE=getPK( )>';
echo '<SELECT NAME=author_pk SIZE=20 COLS=20>';

while ($rows = mysql_fetch_obj ect($result)) {
echo '<OPTION VALUE='.$rows->id.'>'.
$rows->TITLE.' '.
$rows->lastname.', '.
$rows->firstname.
$rows->middlename.
$rows->SUFFIX.
'</OPTION>';
}
echo '</SELECT>';
echo '</FORM>';
//echo '<script language=Javasc ript>';
//echo 'function getPK() {';
//echo
"document.autho r.author_pk.opt ions[document.author .author_pk.sele ctedIndex].
value
";
//echo '}';
//echo "</script>";
I really just know the basics of javascript, but:

--------------------------------------------------------
<script type="text/javascript">
function getPK(arg){
alert(arg);
}
</script>
<form name="testform" >
<select name="author_pk " size="20"
onchange="getPK (this.options[this.selectedIn dex].value)">
<option value="first">f oo</option>
<option value="another" >bar</option>
<option value="last">ba z</option>
</select>
</form>
--------------------------------------------------------

or alternatively:
--------------------------------------------------------
<script type="text/javascript">
function getPK(){

alert(document. testform.author _pk.options[document.testfo rm.author_pk.se lect
edIndex].value);
}
</script>
<form name="testform" >
<select name="author_pk " size="20"
onchange="getPK (this.options[this.selectedIn dex].value)">
<option value="first">f oo</option>
<option value="another" >bar</option>
<option value="last">ba z</option>
</select>
</form>
--------------------------------------------------------

or, if you make & know an ID:
--------------------------------------------------------
<script type="text/javascript">
function getPK(){
selectbox = document.getEle mentById('autho r_pk');
alert(selectbox .options[selectbox.selec tedIndex].value);
}
</script>
</head>
<body>
<form name="testform" >
<select id="author_pk" name="author_pk " size="20" onchange="getPK ()">
<option value="first">f oo</option>
<option value="another" >bar</option>
<option value="last">ba z</option>
</select>
</form>
--------------------------------------------------------

That's how you can get the value.

Now, passing it back to PHP? That will require a trip to the server, and why
would you want to know it before the form is submitted? As it requires a
trip to the server, you could just as easily read the $_POST value.

If you want to do something on your page after selecting the something, you
either should have sent al the relevant info to the server in the HTML or in
js, or you'd have to make use of XMLHTTPRequests
(http://ajaxpatterns.org/XMLHttpRequest_Call).

That's going a bit to far in this group, I'd say: check the pointers, and if
things are unclear, ask comp.lang.javas cript.

--
Rik Wasmus
Jul 14 '06 #9
IchBin wrote:
I am following this thread because I am trying to do something simular.
That is pass value back to php on a select ONCHANGE=. Problem is I do
not know php\javascript all that well. I had posted my code to this
newsgroup but received no answer. So I do not know if I can do what I am
trying to do or I am just so far off that it does not warent an answer.
This is what I have so far. I can not get to work and have comment out
what I am trying:

//
// Handle the data coming back
echo '<FORM NAME=author method=post action='.$_SERV ER['PHP_SELF'].'>';
//echo '<SELECT NAME=author_pk SIZE=20 COLS=20 ONCHANGE='.$_PO ST[id].'>';
//echo '<SELECT NAME=author_pk SIZE=20 COLS=20 ONCHANGE=getPK( )>';
echo '<SELECT NAME=author_pk SIZE=20 COLS=20>';

while ($rows = mysql_fetch_obj ect($result)) {
echo '<OPTION VALUE='.$rows->id.'>'.
$rows->TITLE.' '.
$rows->lastname.', '.
$rows->firstname.
$rows->middlename.
$rows->SUFFIX.
'</OPTION>';
}
echo '</SELECT>';
echo '</FORM>';
//echo '<script language=Javasc ript>';
//echo 'function getPK() {';
//echo
"document.autho r.author_pk.opt ions[document.author .author_pk.sele ctedIndex].value
";
//echo '}';
//echo "</script>";
IchBin:
You don't need to use javascript at all to do what you want to do.
You can simply let PHP do all the work.
Take a look at this example based upon your posting:

<?php
// an example of a monolithic form processor in php
// connect to mysql database
// @note: add a lot more error checking.
mysql_connect($ hostname, $username, $password);
mysql_select_db ($database);

// This form uses the POST method, so process any post selections here
if( isset($_POST['author_pk']) ) {
// do whatever you need to do with the author_pk
$sql = "select * from book_detail where author_pk = {$_POST['author_pk']}";
$detail = mysql_query($sq l);
}

// main form query
$sql = "SELECT * from users order by lastname, firstname, middlename ";
$result = mysql_query($sq l);

mysql_close();
?>
<FORM NAME="author" method="post" action="<?php echo
$_SERVER['PHP_SELF'];?>"
<SELECT NAME="author_pk " SIZE="20" COLS="20">
<?php
// a loop to populate the select options
while( $row = mysql_fetch_obj ect($result) ) {
printf("<option value=\"%d\">%s , %s, %s, %s, %s</option>\n",
$row->id, $row->TITLE, $row->lastname,
$row->firstname, $row->middlename, $row->SUFFIX);
}
mysql_free_resu lt($result);

// display any book details based on the user's selection
if( isset($detail) ) {
while( $row = mysql_fetch_ass oc($detail) ) {
printf("Title: %s<br>\n", $row['title']);
}
}
?>
</SELECT>
</FORM>

Jul 14 '06 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
21492
by: Kim Forbes | last post by:
Hello all, I have simple function that I call from an alert box alert(testScore); It works fine. Unfortunately, I do not like the sound and Exclamation point icon that appears. I'd like a nice message box like VBA message box #64 to appear. I know hardly anything at all about VB or VBA. But, I do know you can call a VB function from Javascript. How? Is it
14
9605
by: Michael Winter | last post by:
In an attempt to answer another question in this group, I've had to resort to calling the DOM method, Node.removeChild(), using a reference to it (long story...). That is, passing Node.removeChild. In Opera (7.23/Win), the call appears to do nothing - the node remains - but no errors are shown. In Netscape (7.0/Win), an exception results. On IE (6.0/Win), the node is removed. Strangly, if I pass another function reference, say...
5
25859
by: elsenraat_76 | last post by:
Hello! I was wondering if someone could help me out with a problem I'm having? I'm trying to input a javascript value into an anchor tag (from a function), but don't have an event to call the function...if that makes sense. Here's what I mean... I have a javascript array set up like so: <script language="javascript" TYPE="text/JavaScript"> //custom object constructor
18
12710
by: Simula | last post by:
I am developing an HTML javascript application and I want to preserve state in a way that can be book-marked. I chose HTML anchors as a means of preserving state. When the application changes state, the HTML page URL would change from default.html to default.html#stateA. example: http://pearstudios.com/javascript/locationHashAndFlash.html This has worked perfectly within HTML and javascript alone, however, when connecting Flash and...
10
2484
by: Tony Rice | last post by:
If I've loaded a set of functions in a webdocument like this: <script language="JavaScript" type="text/javascript" src="/js/foo.js"</script> Shouldn't I be able to call a function from inside foo.js later in that same document by doing something like this: <script language="JavaScript" type="text/javascript">myfunction(myargs)
3
2809
by: Tanmaya Kulkarni | last post by:
Hi, I have a web application where I need to call backend C#/VB.Net functions from javascript. Is it possible..and how? Thanks, Tanmaya
16
2037
by: deepres | last post by:
Hi, I have the following problem. In my application I'm dynamically replacing some of web-page content. For example, I have something like that: <span id="ui_tr_22_1_treeJ_span" > <div id="ui_tr_22_1_treeJ"></div> <script type="text/javascript">
4
2398
omerbutt
by: omerbutt | last post by:
hi there i am making an application in which i have a drop down menu which onchange passes a value(this.value) to a js function which gets the value and calls an ajax routine and passes that value to a php page and then takes back the response ,i have done it all but now i was trying to encrypt the information or the string or the value that is passed through the drop down menu and concatinated with the url and passed to that page and then on...
4
3594
by: raghuvendra | last post by:
Hi I have a jsp page with 4 columns: namely Category name , Category order, Input field and a submit button. All these are aligned in a row. And Each Category Name has its corresponding Category order, Input field and a submit button. The Category name is being fetched from the oracle db along with the corresponding Category order. In the corresponding input field (text box) the user enters a new category order which gets stored in the...
0
9813
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10835
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10585
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9367
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6976
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5645
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5818
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4447
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
4007
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.