Confirm box only cancels

Javascript coding ..

Moderators: macek, egami, gesf

MikeSpider
New php-forum User
New php-forum User
Posts: 49
Joined: Sun Feb 05, 2012 12:48 pm

Confirm box only cancels

Postby MikeSpider » Tue Jul 24, 2012 8:12 am

Hi guys,
I have a form that submit values to a db via post method. I made a confirm box to pop up when the values are out of range of what is expected, the thing is that it's not working properly.

The php & javascript:

Code: Select all

<?php

...

$dont_run = "true";
 if($_soldfor < $_boughtfor || $_soldfor < $existing_cost){
                       ?>
<script type="text/javascript">
                       <!--

      var nP = confirm("You are seling a product for less than you bought! are you sure you want to make this sale?")
      if(nP){

        <?php   $dont_run = false;
         $message = "<b class='negative_msg'>you sold an item for less than you bought!</b>";?>

      }else{
         <?php  $message = "<b class='negative_msg'>Sale cancelled!</b>";
          $dont_run = true; ?>
      }
         
   
      //-->
    </script>
<?php
                   }

           

     if( $dont_run == false){
         
        $insert_raw = new Product();
      ...
?>


Any help will be appreciated,
Mike

User avatar
Nullsig
php-forum Fan User
php-forum Fan User
Posts: 981
Joined: Thu Feb 17, 2011 6:52 am
Location: Racine, WI

Re: Confirm box only cancels

Postby Nullsig » Tue Jul 24, 2012 8:16 am

You cannot call PHP inside of your JavaScript. You are trying to execute Server-side actions after the server has finished processing and served up data.

http://www.virtualshowrooms.co.za/articlepage.php?cp=101

MikeSpider
New php-forum User
New php-forum User
Posts: 49
Joined: Sun Feb 05, 2012 12:48 pm

Re: Confirm box only cancels

Postby MikeSpider » Tue Jul 24, 2012 8:42 am

Nullsig wrote:You cannot call PHP inside of your JavaScript. You are trying to execute Server-side actions after the server has finished processing and served up data.

http://www.virtualshowrooms.co.za/articlepage.php?cp=101


What should I do then?
I want the php script to execute only if the user presses "ok",.

MikeSpider
New php-forum User
New php-forum User
Posts: 49
Joined: Sun Feb 05, 2012 12:48 pm

Re: Confirm box only cancels

Postby MikeSpider » Tue Jul 24, 2012 3:43 pm

I took the php out of JS. but still, the confirm box apears, but the php code runs either way if i press "Ok" or "Cancel".
please help.

Code: Select all

...
   if($_soldfor < $_boughtfor || $_soldfor < $existing_cost){
                       ?>
<script type="text/javascript">
                       <!--

       confirm("You are seling a product for less than you bought! are you sure you want to make this sale?")   
   
      //-->
    </script>
<?php
                   }
                           
        $insert_raw = new Product();
         ...
<?php


User avatar
Nullsig
php-forum Fan User
php-forum Fan User
Posts: 981
Joined: Thu Feb 17, 2011 6:52 am
Location: Racine, WI

Re: Confirm box only cancels

Postby Nullsig » Wed Jul 25, 2012 5:46 am

Your confirm box result is not being saved, and you are not acting on the result. You removed the PHP but didn't replace the logic with client side logic.

MikeSpider
New php-forum User
New php-forum User
Posts: 49
Joined: Sun Feb 05, 2012 12:48 pm

Re: Confirm box only cancels

Postby MikeSpider » Wed Jul 25, 2012 7:48 am

Nullsig wrote:Your confirm box result is not being saved, and you are not acting on the result. You removed the PHP but didn't replace the logic with client side logic.


Right.
I'm using this:

Code: Select all

<script type="text/javascript">
                       <!--
                       
     var np= confirm("You are seling a product for less than you bought! are you sure you want to make this sale?")
        if(np != true)
          return false;
         
   
      //-->
    </script>
<?php ....

 ?>

the "return false" is underlined as invalid return.
Can you help me on how to do this?
Thanks
Mike


Return to “JavaScript”

Who is online

Users browsing this forum: No registered users and 1 guest