Re: Running PHP code into JavaScript if-else clause

From: Date: Mon, 11 Nov 2002 19:46:49 +0000
Subject: Re: Running PHP code into JavaScript if-else clause
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-123877@lists.php.net to get a copy of this message
Php runs on the server, JavaScript runs on the browser. If your function "CheckNumber( $numero )" validates true, the script is going to out put your JavaScript, but the JavaScript will NOT change your php values no matter what the user selects. Wagner Marini wrote:
JavaScrip and PHP together Hey ALL, I really do not understand what's going on. In my code below I try to inform the user that the number added to him already exists in database but in my JavaScrit's if-else the line "<?php $tst = TRUE; ?>" ever run, even the user wants to add the number. What's happened?? Thanks, WMarini/ ---------------------------------------------------------------------------- --- ... <body> <?php $tst = FALSE; ...
    $contact_ins = "insert into contato (nome) values ('$name');";
    mysql_query( $contact_ins ) OR die( mysql_error() );
    //Check if numero exists.
    if( CheckNumber( $numero ) ) {
?>
       <script language="JavaScript">
         if ( window.confirm("Number to be added exists.\nContinue?") ) {
           //The user wants to add the number defined.
           <?php $tst = FALSE; ?>
           break;
         }
         else {  //User does not want to add the number.
           <?php $tst = TRUE; ?>
           ;
         }
       </script>
<?php
      }
       if( $tst == FALSE ) {
         //Add the number, Don't care!
          ...
       }
... ?> </body> </html> ---------------------------------------------------------------------------- --- -- Wagner Marini ----
-- By-Tor.com It's all about the Rush http://www.by-tor.com

« previous php.general (#123877) next »