Jump to content

use php inside javascript promt box code?


samoht

Recommended Posts

Hello all,

 

I have a question about mixing js and php. I have a checkout section on my site that ends in a confirmation page that has a table of of the ordered items - at this point I want to ask the client if they have a coupon - so I accomplished that by an input button that on click goes to this js function:

 

function javascript_prompt_for_coupon() {

// PROMPTS REQUIRE TWO ARGUMENTS
var message = "Please Enter Your Code";
var promo_code = "6 digit code goes here";

var return_value = prompt(message,promo_code);

// TEST TO SEE IF NULL OR STRING RETURNED
if (return_value != null) {
	// 'OK' SCRIPT GOES HERE
	// This where I want to use php!
} else {
	// 'CANCEL' SCRIPT GOES HERE
}
}

If I can use php here then I would like to update my HTML table with the coupon added. This actually sounds like a job for AJAX

 

Any IDeas??

 

 

Link to comment
Share on other sites

What you are trying to do in your example is definetly an ajax solution. Why not just give an input box for the user to enter a coupon code on the confirmation page if they have one.

 

Once they confirm their order do your checking with php and then update the db.

Link to comment
Share on other sites

That is what I'd like to do - but my boss wants everything on one page. He does not want to leave the current page expect to submit the order. So I guess I'll have to go with AJAX - and id I do - I could still use the prompt?

 

My question is then, once I pass the promo_code to the AJAX - search my db for the discount and return that value, how do I write the table structure to update properly?

 

here is a example of my current structure:

<?php
          $numItem  = count($cartContent);
          $subTotal = 0;
          for ($i = 0; $i < $numItem; $i++) {
            extract($cartContent[$i]);
            $subTotal += $PriceSell * $qty;
          ?>
          <tr class="labelcell">
            <td class="content">
              <?php echo "$qty x $Name"; ?>
            </td>
            <td align="right">
              <?php echo displayAmount($PriceSell); ?>
            </td>
            <td align="right">
              <?php echo displayAmount($qty * $PriceSell); ?>
            </td>
          </tr><?php
          }
          ?>
          <tr class="labelcell">
            <td colspan="2" align="right">
              Sub-total
            </td>
            <td align="right">
              <?php echo displayAmount($subTotal); ?>
            </td>
          </tr>
          <tr class="labelcell">
            <td colspan="2" align="right">
              Shipping
            </td>
            <td align="right">
              <?php echo displayAmount($shopConfig['shippingCost']); ?>
            </td>
          </tr>
          <tr class="labelcell">
            <td colspan="2" align="right">
              Total
            </td>
            <td align="right">
              <?php echo displayAmount($shopConfig['shippingCost'] + $subTotal); ?>
            </td>
          </tr>
        </table>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.