Print (" if (Confirm(\" blah blah blah

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Deddog
Forum Commoner
Posts: 55
Joined: Thu Sep 26, 2002 6:05 am
Location: Brighton

Print (" if (Confirm(\" blah blah blah

Post by Deddog »

Is it possible to combine php with dynamic javascript. Or do i need a rethink?

If an entered name is already on the databse, then i want to make the user aware of this and give them the option not to input the data. I have left this verification until after the input form has been submitted.

Many thanks for help and advice in advance.


// checks if the name is already in the database. If it is already there then
// it return how many times.
$NameExists = VerifyName($FName,$LName);

if ($NameExists >=1):
print(" <SCRIPT LANGUAGE=\"JavaScript\"> ");
print(" if (confirm(\" $NAME already exists in the database $NameExists
times Do you wish to continue?\")){ ");
print(" </script> ");
echo "<font face=Arial size=+0 color=\"#CC0000\"><b>$NAME has
been added to the database</b></font><br>";
AddContact($FName,$LName,$Spd,$Mbl,$E_M,$WPhone,
$Department,$JTitle,$EasyList);
print(" <SCRIPT LANGUAGE=\"JavaScript\"> ");
print(" }</script> ");
else:
echo "<font face=Arial size=+0 color=\"#CC0000\"><b>$NAME has
been added to the database</b></font><br>";
AddContacts($FName,$LName,$Spd,$Mbl,$E_M,$WPhone,
$Department,$JTitle,$EasyList);
endif;
User avatar
Johnm
Forum Contributor
Posts: 344
Joined: Mon May 13, 2002 12:05 pm
Location: Michigan, USA
Contact:

Post by Johnm »

Yes, you can have PHP write JavaScript in output to the browser, but not the way you have it written.

First, read the sticky refering to JS at the top of this forum.

Second, after reading it, look at your code and you will probably see what is wrong.

Third, if you are then still having problems, post your new code and likely someone will help.

In essence, JS can manipulate PHP variable contents but it doesnt work the other way around.

John M
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

for clarification: JS(client-side) actually does not manipulate PHP-variables but it can be used to send parameters to PHP(server). Both parts are running at diffrent times. the PHP.script creates a document that is sent to the client. The client interprets the datastream and performs (hopefully) appropriate tasks, e.g. executing the javascript. But there is no reverse channel. Only a new request can transmit new values to the server that invokes a new instance of the script, that produces a document, ....
Post Reply