Page 1 of 1

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

Posted: Mon Dec 09, 2002 10:20 am
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;

Posted: Mon Dec 09, 2002 12:02 pm
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

Posted: Mon Dec 09, 2002 12:52 pm
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, ....