php math addition from form

Discussion in 'Programming' started by webber09, Sep 10, 2009.

  1. #1
    this is a very quick example of the kind of content I will have.

    <form>
    Required bit rate
    <select>
      <option>128kbps</option>
      <option>192kbps</option>
      <option>240kbps</option>
      <option>320kbps</option>
    </select><br />
    Required listener ammount
    <select>
      <option>up to 100</option>
      <option>up to 200</option>
      <option>up to 400</option>
      <option>400+</option>
    </select><br />
    Auto DJ? 
    <select>
      <option>Yes</option>
      <option>No</option>
    </select>
    </form>
    Code (markup):
    what i need is for the form to detect the value selected in the <option> and, depending on which are selected, add a set amount of money for each <option> and give a final total at the end =]
     
    webber09, Sep 10, 2009 IP
  2. girlzlover12

    girlzlover12 Active Member

    Messages:
    127
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    51
    #2
    I have made something like this for the advertisement page for my iphones website.

    I made an array of prices in the config file and set the select values for each drop down to 0-4 (I have 5 options).

    then when the form is submitted I have $array[$dropdown_value] for each of the options. then you form your equation $total = $array[$dropdown_value]*$array2[$dropdown_value2]. This is way you insert a number to select the right value out of the array and then performs a math equation.

    If you look at the advertising page on http://myiphonebackgrounds.com you may get a better idea of what Im talking about. I use this to generate a paypal payment button.

    A second option is to set each drop down value to the actual money amount then just perform the operation. using an array allows you to change the prices faster.

    If you will give me a link on your website I will make you a quick script to do all of this for you. PM me if your interested.

    edit: I just noticed in your code your missing the value attribute <option value="0" selected>Top Banner</option> (ex. from my website)
     
    Last edited: Sep 10, 2009
    girlzlover12, Sep 10, 2009 IP
  3. pneulameiro

    pneulameiro Peon

    Messages:
    440
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    0
    #3
    I think that the only you can do this is with javascript "document.write(...". But do you need to do this in a php script?
     
    pneulameiro, Sep 10, 2009 IP
  4. premiumscripts

    premiumscripts Peon

    Messages:
    1,062
    Likes Received:
    48
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Well, looks like you can't even properly structure the html (the selects have no name, the options no value) so it's best if you place this in the buy & sell (hire) section, unless there is a generous soul at there that wants to do this all for you.
     
    premiumscripts, Sep 10, 2009 IP
  5. SecureCP

    SecureCP Guest

    Messages:
    226
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #5
    what premium scripts said. This seems like you're not too sure what you're doing.
     
    SecureCP, Sep 10, 2009 IP
  6. girlzlover12

    girlzlover12 Active Member

    Messages:
    127
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    51
    #6
    neither one of you seems very helpful especially since I already offered to help. In addition its quite easy and I can do it in php because that is exactly how I generate my paypal buttons. It does seem like he may need someone to help him because his code is missing several things.

    Try using Dreamweaver to generate your forms.
     
    girlzlover12, Sep 10, 2009 IP
  7. premiumscripts

    premiumscripts Peon

    Messages:
    1,062
    Likes Received:
    48
    Best Answers:
    0
    Trophy Points:
    0
    #7
    Sorry, I'm just not much of a fan of people asking for complete solutions / scripts when they don't know much if any PHP. This forum is intended for people that are trying to learn PHP or want help with a specific bug. Otherwise, the user should just hire someone. Anyway, I think it's great of you to help the user with this. I just don't want to encourage threads like these.
     
    premiumscripts, Sep 10, 2009 IP
  8. webber09

    webber09 Active Member

    Messages:
    131
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    71
    #8
    thankyou girlzlover12, i will pm you shortly with my website address. as for the other slightly less concerning people... i know what i am doing with forms, however as i said it was a quick example of what i need, i know that they needed the values and other information to work once its online, i was just showing how i wanted it =]
     
    webber09, Sep 11, 2009 IP
  9. pneulameiro

    pneulameiro Peon

    Messages:
    440
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    0
    #9
    no problem man, I think that I just misunderstood you, because I was searching for more information to be able to help you. good luck with your solution.
     
    pneulameiro, Sep 11, 2009 IP
  10. webber09

    webber09 Active Member

    Messages:
    131
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    71
    #10
    thank you anyway (above)
     
    webber09, Sep 12, 2009 IP