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 6 of 6
  1. #1
    Regular Coder
    Join Date
    Jan 2005
    Posts
    189
    Thanks
    6
    Thanked 0 Times in 0 Posts

    Showing and Hiding Form Fields

    I have a form that is somewhat long, so I'd like to only show certain fields if they are necessary, but my code isn't working. Is there an easier way to do this, or do I just need to fix something??

    What I want here is a selection box where users can choose to be paid via paypal or by check.

    Code:
    <select name="payment">
    <option value="" <?php if($_POST["payment"] == ""){ echo('selected="selected"'); } ?>>Select Payment Method</option>
    <option value="Check" <?php if($_POST["payment"] == "Check"){ echo('selected="selected"'); } ?>>Check</option>
    <option value="Paypal" <?php if($_POST["payment"] == "Paypal"){ echo('selected="selected"'); } ?>>Paypal</option>
    </select>
    Please select the method you would like:
    
    <?php if($_POST["payment"] == "Check"){ 
           echo('check details and fields will go here if applicable'); }
    if($_POST["payment"] == "Paypal"){
           echo('paypal information will go here if applicable'); }
    if($_POST["payment"] == ""){
           echo('make a selection</font>');}
    			?>

  • #2
    UE Antagonizer Fumigator's Avatar
    Join Date
    Dec 2005
    Location
    Utah, USA, Northwestern hemisphere, Earth, Solar System, Milky Way Galaxy, Alpha Quadrant
    Posts
    7,691
    Thanks
    42
    Thanked 637 Times in 625 Posts
    What isn't working?

  • #3
    Regular Coder
    Join Date
    Jan 2005
    Posts
    189
    Thanks
    6
    Thanked 0 Times in 0 Posts
    Instead of showing what's selected, the menu selection menu is on "paypal" and it just says "'paypal information will go here if applicable" underneath.

    It looks like it's just setting the variable to paypal.

  • #4
    UE Antagonizer Fumigator's Avatar
    Join Date
    Dec 2005
    Location
    Utah, USA, Northwestern hemisphere, Earth, Solar System, Milky Way Galaxy, Alpha Quadrant
    Posts
    7,691
    Thanks
    42
    Thanked 637 Times in 625 Posts
    I see... forgive the obvious question, but is the value of $_POST['payment'] = "Paypal"? Because that seems to be the only way it would select Paypal as the default. If $_POST['payment'] shouldn't be = "Paypal", then you'll need to explain how it gets set to something different and where it then gets changed to Paypal. From the small snippet of code you're showing, I can't tell what could be wrong.

  • #5
    Regular Coder
    Join Date
    Jan 2005
    Posts
    189
    Thanks
    6
    Thanked 0 Times in 0 Posts
    The code I was using is a javascript that basically says show or hide the field based on what is selected from a dropdown. I found the problem was that there was only the option to show or hide. What I'm looking for is a snippet or something where I can specify what is shown based on selection.

    Like if you had a Country Selection box and say I pick USA, then it shows "states" instead of say "provinces" or "territories" etc..

  • #6
    Regular Coder logictrap's Avatar
    Join Date
    Apr 2008
    Posts
    155
    Thanks
    11
    Thanked 3 Times in 3 Posts
    if you want the options updated without reloading the page (ie clicking a submit button) you'll have to use javascript as php requires a page refresh.

    You might be able to find some sample code on the jquery.com site.

    Which came first - the chicken or the egg? The egg... [ticket closed]
    If a tree falls... does it make a sound? Yes.............. [ticket closed]


  •  

    Posting Permissions

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