Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 10 of 10
  1. #1
    New Coder
    Join Date
    Jul 2007
    Posts
    24
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Change text box value based on drop down value selected

    The form below is a simple checkout form with a select box that allows users to choose the number of email accounts they want when they check out of our website and posts the user's drop down selection's value to the url string via get.

    The number of email accounts are 1, 3, and 6 email accounts. I'm trying to assign a dollar value to each option that will display in a text box (it says $TBA in example below) depending on the user's choice from select box.

    Example: User chooses 1 email box, so $5 displays where $TBA is or user chooses 6 email accounts and $10 displays where $TBA is.... we just want the $TBA to change to reflect the cost of the email accounts based on the user's chosen number of email accounts from drop down select box....

    Any feedback on how to accomplish this is appreciated!

    Code:
    <form action="/accounts/cart.php" method="get">
    <table class="comparison pricing-email" border="0" cellspacing="1" cellpadding="0" width="100%">
    <tbody>
    <tr class="row1">
    <td class="col1">Choose # of EMAIL accounts:</td>
    <td>
    <select style="width: 60px; font-size: 17px;" name="a=add"> <option value="1">1</option> <option value="3">3</option> <option value="4">6</option> </select>
    </td>
    <td></td>
    </tr>
    <tr class="row1">
    <td class="col1">Per Month:</td>
    <td>$TBA</td>
    <td>
    <input type="image" src="/wp-content/themes/leadpress/images/sign-up.png" alt="Sign Up" /></input>
    </td>
    </tr>
    </tbody>
    </table>
    </form>

  • #2
    Master Coder
    Join Date
    Jun 2003
    Location
    Cottage Grove, Minnesota
    Posts
    9,472
    Thanks
    8
    Thanked 1,085 Times in 1,076 Posts
    Is a page refresh OK, or are you planning on using some Javascripting along with PHP?

    You might want to post this in the Javascripting section?

  • Users who have thanked mlseim for this post:

    diesel12 (09-29-2009)

  • #3
    New Coder
    Join Date
    Jul 2007
    Posts
    24
    Thanks
    2
    Thanked 0 Times in 0 Posts
    Great question. The answer is I don't know.... I suspected that javascript may be necessary... but am not really sure.... am not familiar with refresh or javascript in terms of writing the necessary code.... Does it look like one of these will be necessary to achieve our goal?

  • #4
    Master Coder
    Join Date
    Jun 2003
    Location
    Cottage Grove, Minnesota
    Posts
    9,472
    Thanks
    8
    Thanked 1,085 Times in 1,076 Posts
    Below is my shot at it ....
    I'm no Javascript expert though.
    The result (price) ends-up in a text box, but maybe it doesn't have to be? not sure.

    Maybe enough there to get some ideas ... again, you should ask the JS experts.

    Copy and save this as "test.html" and open it with your browser to test it out...
    PHP Code:
    <html>
    <
    head>
    </
    head>
    <
    script type="text/javascript">
    function 
    addit(){
        if(
    document.getElementById("add").value=="1")
        {
            
    document.getElementById("amount").value="$5.00"
        
    }
        if(
    document.getElementById("add").value=="3")
        {
            
    document.getElementById("amount").value="$10.00"
        
    }
        if(
    document.getElementById("add").value=="6")
        {
            
    document.getElementById("amount").value="$15.00"
        
    }
    }
    </script>
    <body>
    <form action="/accounts/cart.php" method="get">
    <table class="comparison pricing-email" border="0" cellspacing="1" cellpadding="0" width="30%">
    <tbody>
    <tr class="row1">
    <td class="col1">Choose # of EMAIL accounts: &nbsp;
    <select style="width: 60px; font-size: 17px;" name="add" id="add" onChange="addit()">
    <option value="1">1</option>
    <option value="3">3</option>
    <option value="6">6</option>
    </select>
    </td>
    </tr>
    <tr class="row1">
    <td class="col1">Per Month: <input type="text" id="amount" value="" style="border:none; font-size:13pt;"></td>
    </tr><tr>
    <td>
    <input type="submit" name="submit" value="Sign-Up">
    </td>
    </tr>
    </tbody>
    </table>
    </form>
    </body>
    </html> 

  • Users who have thanked mlseim for this post:

    diesel12 (09-30-2009)

  • #5
    New Coder
    Join Date
    Jul 2007
    Posts
    24
    Thanks
    2
    Thanked 0 Times in 0 Posts
    MSELM,

    I truly appreciate your willingness to help me out with this! It is greatly appreciated!!!

    Thanks,

    Trace

  • #6
    New to the CF scene
    Join Date
    Oct 2010
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Now would if i wanna add another row how do i make it add on to it

  • #7
    New to the CF scene
    Join Date
    Oct 2010
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts
    And have them add together

  • #8
    Master Coder
    Join Date
    Jun 2003
    Location
    Cottage Grove, Minnesota
    Posts
    9,472
    Thanks
    8
    Thanked 1,085 Times in 1,076 Posts
    I don't know what "row" means ...

    row, column, another text box ????

  • #9
    New to the CF scene
    Join Date
    Oct 2010
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts
    like how do i add another drop down box that wil make it so it adds to the total price

  • #10
    New to the CF scene
    Join Date
    Feb 2014
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    code for show textbox value according to selected drop down

    <html>
    <head>
    </head>
    <script type="text/javascript">
    function addit(){
    if(document.getElementById("add").value=="")
    {
    document.getElementById("amount").value=""
    }
    if(document.getElementById("add").value=="1")
    {
    document.getElementById("amount").value="$5.00"
    }
    if(document.getElementById("add").value=="3")
    {
    document.getElementById("amount").value="$10.00"
    }
    if(document.getElementById("add").value=="6")
    {
    document.getElementById("amount").value="$15.00"
    }
    }
    </script>
    <body>
    <form action="/accounts/cart.php" method="get">
    <table class="comparison pricing-email" border="0" cellspacing="1" cellpadding="0" width="30%">
    <tbody>
    <tr class="row1">
    <td class="col1">Choose # of EMAIL accounts: &nbsp;
    <select style="width: 60px; font-size: 17px;" name="add" id="add" onChange="addit()">
    <option value="">Select</option>
    <option value="1">1</option>
    <option value="3">3</option>
    <option value="6">6</option>
    </select>
    </td>
    </tr>
    <tr class="row1">
    <td class="col1">Per Month: <input type="text" id="amount" value="" style="border:none; font-size:13pt;" readonly="readonly"></td>
    </tr><tr>
    <td>
    <input type="submit" name="submit" value="Sign-Up">
    </td>
    </tr>
    </tbody>
    </table>
    </form>
    </body>
    </html>


  •  

    Posting Permissions

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