0

i can get the $amount to show up on the page, but after I get a error telling me i need to add in an amount for it to run through the script

i just need the $amount to be added by the $payment, $donation, and post the $amount

<label>Payment:</label>
<input name="payment" id="payment" class="small-field" value="<?php echo $payment;?>"   />
*
<div class="clr"></div>

<label>Donation:</label>
<input type="checkbox"  id="donation" name="donation" value="1.00"  />

<div class="clr"></div>

<?php echo $amount;?>
Peon
  • 7,902
  • 7
  • 59
  • 100

2 Answers2

2

I think you mean JavaScript ( or jQuery package might be easier for you ).

  1. Set up an event for checkbox;
  2. Catch the value of the checkbox;
  3. Add +1 to the value;
  4. Replace the original value with the newly created one;

If I understand you correctly. Here is an example on how to do it.

<html>
  <head>
    <title>Test page</title>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <meta name="author" content="Dainis Abols" />
    <script src="http://code.jquery.com/jquery-latest.js"></script>
  </head>
  <body>

    <input id="check2" type="checkbox" name="test" value="1">
    <div id="check1" style="float: left;">1.00</div>

    <!-- The event for checkbox with id 'check2' -->
    <script>
    $("#check2").click(function() {
        var value = $(this).val(); /* Catching value of checkbox */
        value++; /* Increasing value by one */
        $(this).val(value); /* Replacing original value */
        $(this).attr('checked', false); /* Removing CHECKED ( if needed ) */
        $('#check1').html(value + '.00'); /* Just for visual aid */
    });
    </script>
    <!-- End of event -->

  </body>
</html>
Community
  • 1
  • 1
Peon
  • 7,902
  • 7
  • 59
  • 100
  • What an answer. It was explained as question was asked :-) – Exception Jan 31 '13 at 13:34
  • 1
    Well, I wrote the steps on doing it. Some knowledge from OP is also required. – Peon Jan 31 '13 at 13:45
  • Sorry guys, this is a little over my head. I can setup php scripts and mysql programs all day long because it tell you how. Now when it comes to adding in a check box to add $1.00 if you would like to make a donation i'm almost clueless. – Troy Prescott Jan 31 '13 at 14:06
  • @TroyPrescott I updated the answer with demo code. Just keep clicking the checkbox and see how the value increases. – Peon Jan 31 '13 at 16:18
0

If you wan't to change some php value with html script you'll need a form to post information to server, or use ajax to do this.

Php works just on server side, your HTML page are on client side. Both don't interact each other.

I recomend use ajax to do that in "real time". Something like that: http://api.jquery.com/jQuery.ajax/

$(function () {
$("#payment").bind('change',function () {   
    if($(this).checked){
    $.ajax({
        type: "GET",
        url: "test.php",            
        success: function(){
            alert('value as incremented by 1');
        }
    });
    }
});

});

Guerra
  • 2,792
  • 1
  • 22
  • 32