www.webdeveloper.com
Results 1 to 2 of 2

Thread: PHP and Java script calculations

  1. #1
    Join Date
    Dec 2010
    Location
    South Africa
    Posts
    2

    PHP and Java script calculations

    Dear JPnyc
    I have a PHP script which pulls mysql data to my page. I have however endless trouble to use javascript with it as I am using a select dropdown box and cant find my way through it.
    This is what I am trying to do:
    I have a text field with existing credits which is on the ad, but then I have a dropdown select box next to it. The idea here is to add additional funds to the ad which changes live as the client clicks on his desired rates. I have also a Total available funds, and need this to go down when the client picked his desired amount. Also if he cancel his selection, the amount must then be placed back into the total available funds.

    Here is the code which I am busy with:
    PHP Code:
    <?php
    include("config.php");

    $query "SELECT * FROM ads ORDER BY no";
    $result mysql_query($query) or die ("Query failed");
    //let's get the number of rows in our result so we can use it in a for loop
    $numofrows mysql_num_rows($result);
      
    echo 
    "<TABLE BORDER=\"1\">\n";
    echo 
    "<TR bgcolor=\"lightblue\"><TD><b>ID</b></TD><TD><b>CATEGORY</b></TD><TD><b>TITLE</b></TD><td><b>DATE</b></td><td><b>CREDITS</b></td><td><b>ADD CREDITS</b></td><td><b>Flag</b></td><td><b>Edit</b></td><td><b>Delete</b></td></TR>\n";
    for(
    $i 0$i $numofrows$i++) {
    $row mysql_fetch_array($result); //get a row from our result set
    if($i 2) { //this means if there is a remainder
    echo "<TR bgcolor=\"#CCFFCC\">\n";
    } else { 
    //if there isn't a remainder we will do the else
    echo "<TR bgcolor=\"#BFD8BC\">\n";
    }

    echo 
    "<TD>".$row['no']."</TD><TD>".$row['category']."</TD><TD>".$row['title']."</TD><TD>".$row['date']."</TD><TD>".$row['credit']."</TD>
    <td><select name=\"amount\">
    <option value=\"50.00\">50</option>
    <option value=\"60.00\">60</option>
    <option value=\"70.00\">70</option>
    <option value=\"80.00\">80</option>
    <option value=\"90.00\">90</option>
    <option value=\"100.00\">100</option>
    </select>
    <input type=\"image\" src=\"images/arrow1.gif\" alt=\"Submit button\"></td>
    <td>Flag</td><td>Edit</td><td>Delete</td>\n"
    ;

    echo 
    "</TR>\n";
    }
    //now let's close the table and be done with it
    echo "</TABLE>\n";

    echo 
    "Total Available Credits: ";
    echo 
    $row['usr_credit'];

    ?>

  2. #2
    Join Date
    Apr 2003
    Location
    Netherlands
    Posts
    21,654
    Code:
    <form action="#" name="form1">
        <select name="amount"> 
        <option value="50.00">50</option> 
        <option value="60.00">60</option> 
        <option value="70.00">70</option> 
        <option value="80.00">80</option> 
        <option value="90.00">90</option> 
        <option value="100.00">100</option> 
        </select> 
        <p>
            <label>Credit: <input type="radio" name="edit" onclick="this.form.total.value=(parseFloat(this.form.total.value) + parseFloat(this.form.amount.value)).toFixed(2);"></label>
            <label>Debit: <input type="radio" name="edit" onclick="this.form.total.value=this.form.total.defaultValue"></label>
        </p>
        <label>Total Available Credits:<input type="text" name="total" value="50.00" disabled></label>
    </form>

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles