473,883 Members | 1,531 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
13 18696
David Haynes wrote:
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.auth or.author_pk.op tions[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>
David, thank you so much for helping me out. I do not have much more
hair to pull out. I am a Java person. Anyway, I understand a lot more
after you sample code.

As an aside, this is my own little project to learn php and etc. I
already have a complete Java\swing application written around this DB so
I figure I could lean away from J2EE and try PHP. It is a different animal.

This DB is a Quotes DB. I have been building over the last few years.
Just a personal interest. I have around 1300 authors and over 32,000
quotes along with detail\quote like external Links and references for
each quote. And naturally detail information about the author.

I did mix your code with mine. The only problem I am having is with the
dropdown object. When I run the program the following displays: on and
on and not in the dropdown..

, , , , , Abbey, Edward, , , Abbott, William, Alexander, , Abelard,
Pete, , , Accius, Lucius, , , Acheson, Dean, , , Ackerman, Diane, , ,
Adams, Abigail, Smith, , Adams, Ansel, , , Adams, Bryan, , , Adams,
Douglas, , , Adams, Franklin, Pierce, , Adams, Henry, , , Adams, Joey,
Lauren, , Adams, John, , , Adams, John, Quincy, , Adams, Scott, , ,
Addison, Joseph, , , Ade, George, , , Adler, Alfred, , , Adler,
Mortimer, Jerome, , Adorno, Theodor, , , Aeschylus, , , , Aesop, , , ,
Afer, Publius, Terentius, , Agathon, , , , Agesilaus, , , II , Aiken,
George, , , Aiken, Howard, , , Alcott, Amos, Bronson, , Alcott, Louisa,
May, , Alcuinus or Ealhwine, Flaccus, Albinu, , Alda, Alan, , ,
Alexander, Shana, , , Ali-Haj, Muhammad, , , Allen, Fred, , , Allen,
Woody, , , Alzado, Lyle, , , Amiel, Henri-Frédéric, , , Amory,
Cleveland, , , Anaxagoras, , , , Ancient Chinese Curse, , , , Andersen,
Hans, Christian, , Angell, George, Thorndike, , Angelou, Maya, , The
Princess, Anne, , , , Princess Royal , Anonymous, , , , Anouilh, Jean, ,
Saint, Anselm, , , of Canterbury , Anthony, Susan, B., , Antiphanes, , ,
, Antisthenes,

Here is the code but I guess the concern is the dropdown.

<?php
//
// Open DB
include 'library/opendb.php';

// 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
$sqlcmd = 'select id, TITLE, lastname, firstname, middlename, SUFFIX
from author_detail order by lastname, firstname, middlename';
$result = mysql_query($sq lcmd);
if (!$result) {
die('Database Error: ' . mysql_error());
exit;
}
//
// Close DB
include 'library/closedb.php';
?>

<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>

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 #11
IchBin wrote:
David, thank you so much for helping me out. I do not have much more
hair to pull out. I am a Java person. Anyway, I understand a lot more
after you sample code.

As an aside, this is my own little project to learn php and etc. I
already have a complete Java\swing application written around this DB so
I figure I could lean away from J2EE and try PHP. It is a different animal.

This DB is a Quotes DB. I have been building over the last few years.
Just a personal interest. I have around 1300 authors and over 32,000
quotes along with detail\quote like external Links and references for
each quote. And naturally detail information about the author.

I did mix your code with mine. The only problem I am having is with the
dropdown object. When I run the program the following displays: on and
on and not in the dropdown..

, , , , , Abbey, Edward, , , Abbott, William, Alexander, , Abelard,
Pete, , , Accius, Lucius, , , Acheson, Dean, , , Ackerman, Diane, , ,
Adams, Abigail, Smith, , Adams, Ansel, , , Adams, Bryan, , , Adams,
Douglas, , , Adams, Franklin, Pierce, , Adams, Henry, , , Adams, Joey,
Lauren, , Adams, John, , , Adams, John, Quincy, , Adams, Scott, , ,
Addison, Joseph, , , Ade, George, , , Adler, Alfred, , , Adler,
Mortimer, Jerome, , Adorno, Theodor, , , Aeschylus, , , , Aesop, , , ,
Afer, Publius, Terentius, , Agathon, , , , Agesilaus, , , II , Aiken,
George, , , Aiken, Howard, , , Alcott, Amos, Bronson, , Alcott, Louisa,
May, , Alcuinus or Ealhwine, Flaccus, Albinu, , Alda, Alan, , ,
Alexander, Shana, , , Ali-Haj, Muhammad, , , Allen, Fred, , , Allen,
Woody, , , Alzado, Lyle, , , Amiel, Henri-Frédéric, , , Amory,
Cleveland, , , Anaxagoras, , , , Ancient Chinese Curse, , , , Andersen,
Hans, Christian, , Angell, George, Thorndike, , Angelou, Maya, , The
Princess, Anne, , , , Princess Royal , Anonymous, , , , Anouilh, Jean, ,
Saint, Anselm, , , of Canterbury , Anthony, Susan, B., , Antiphanes, , ,
, Antisthenes,

Here is the code but I guess the concern is the dropdown.

<?php
//
// Open DB
include 'library/opendb.php';

// 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
$sqlcmd = 'select id, TITLE, lastname, firstname, middlename, SUFFIX
from author_detail order by lastname, firstname, middlename';
$result = mysql_query($sq lcmd);
if (!$result) {
die('Database Error: ' . mysql_error());
exit;
}
//
// Close DB
include 'library/closedb.php';
?>

<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>
IchBin:
1. I made a mistake in the sample code I sent you in that the <FORM>
tag is not properly terminated. The line should read:
<FORM NAME="author" method="post" action="<?php echo
$_SERVER['PHP_SELF']'?>">
The last '>' was missing.
2. if you run the SQL query from the mysql command line, do you get
what you expect?
Hint:
Add 'echo $sqlcmd;exit;' after the $sqlcmd= line and then cut and
paste into a mysql command session
3. Adjust the sqlcmd and add 'limit 1' so that only one row is returned
while debugging. If it is still not right, post the code and the output
and I'm sure folks here will be all over it offering advice.

-david-

Jul 14 '06 #12
David Haynes wrote:
>
IchBin:
1. I made a mistake in the sample code I sent you in that the <FORM>
tag is not properly terminated. The line should read:
<FORM NAME="author" method="post" action="<?php echo
$_SERVER['PHP_SELF']'?>">
The last '>' was missing.
2. if you run the SQL query from the mysql command line, do you get
what you expect?
Hint:
Add 'echo $sqlcmd;exit;' after the $sqlcmd= line and then cut and
paste into a mysql command session
3. Adjust the sqlcmd and add 'limit 1' so that only one row is returned
while debugging. If it is still not right, post the code and the output
and I'm sure folks here will be all over it offering advice.

-david-
David, thanks for all your help and tips. The sql is correct.

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 #13
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?
print "<scriptalert(' Hello world'); </script>";

(needs some tidying, and watch out for the quotes)

C.
Jul 16 '06 #14

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

Similar topics

3
21494
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
9613
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
25860
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
12716
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
2485
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
2038
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
2400
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
3595
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
9932
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...
1
10833
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
10405
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9558
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
7114
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
5782
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...
1
4602
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
4200
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3227
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.