www.webdeveloper.com
Results 1 to 9 of 9

Thread: [RESOLVED] Retreiving <select> value in $_POST...

  1. #1
    Join Date
    Sep 2008
    Posts
    260

    resolved [RESOLVED] Retreiving <select> value in $_POST...

    I've retrieved values out of form field submit, but this one is a little tricky to me.

    Basically, what the content that appears on a page depends on what value is selected from a drop down on "that particular page". Which means that the page should reload and $_POST should retrieve the value each time a new value is selected in the drop down.

    Now, the conditional statement is already setup..

    PHP Code:

    if (isset($_POST['user_city'])) {

        
    $city_select $_POST['user_city'];
        
        
    $category_id get_cat_ID($city_select);
        
        
    $sub_categories get_categories('child_of='.$category_id);
            
        } else { 
        
        
    $category_id get_cat_ID('atlanta');
        
        
    $sub_categories get_categories('child_of='.$category_id);
        

    I just need to get things working here:

    PHP Code:
                       <select name="user_city" onchange="window.location.reload()" >
                            <
    option value="atlanta">AtlantaGA</option>
                            <
    option value="chicago">ChicagoIl</option>
                        </
    select
    I thought that $_POST would automatically read the value, but I appear to be missing something..any advice?

  2. #2
    Join Date
    Aug 2010
    Location
    Ohio
    Posts
    136
    HTML Code:
    <form action="" method="post">
        <select name="user_city" onchange="window.form.submit()" >
              <option value="atlanta">Atlanta, GA</option>
              <option value="chicago">Chicago, Il</option>
        </select> 
    </form>
    Reload will not submit form data.

  3. #3
    Join Date
    Sep 2008
    Posts
    260
    Quote Originally Posted by NoasIT View Post
    HTML Code:
    <form action="" method="post">
        <select name="user_city" onchange="window.form.submit()" >
              <option value="atlanta">Atlanta, GA</option>
              <option value="chicago">Chicago, Il</option>
        </select> 
    </form>
    Reload will not submit form data.
    Thanks for your response...just tried it and it didn't work..

    The page isn't reloading and it doesn't seem like the select value is being submitted..

    You can have a look at it here http://sociallyaffluent.com/sexyafte...tegory/events/

  4. #4
    Join Date
    Aug 2010
    Location
    Ohio
    Posts
    136
    Sorry my javascript was wrong. It should have been this:
    HTML Code:
    <form name="cityform" action="" method="post">
        <select name="user_city" onchange="this.cityform.submit()" >
              <option value="atlanta">Atlanta, GA</option>
              <option value="chicago">Chicago, Il</option>
        </select> 
    </form>
    I think...

  5. #5
    Join Date
    Oct 2010
    Location
    Ohio
    Posts
    233
    form element might need an id instead of/in addition to name. Not sure on this tho.
    ~Ryan
    www.rdennispallas.com <-- Personal Site, changing regularly cuz its ugly.

  6. #6
    Join Date
    Jan 2006
    Location
    England UK
    Posts
    200
    Hey ya could try this:

    HTML Code:
    <form id="cityform" action="" method="post">
        <select name="user_city" onchange="javascript:document.cityform.submit()" >
              <option value="atlanta">Atlanta, GA</option>
              <option value="chicago">Chicago, Il</option>
        </select> 
    </form>
    But i am no pro coder but i have done this before but using $_GET rather then $_POST
    What's PHP? Well ermm

  7. #7
    Join Date
    Sep 2008
    Posts
    260
    Quote Originally Posted by NoasIT View Post
    Sorry my javascript was wrong. It should have been this:
    HTML Code:
    <form name="cityform" action="" method="post">
        <select name="user_city" onchange="this.cityform.submit()" >
              <option value="atlanta">Atlanta, GA</option>
              <option value="chicago">Chicago, Il</option>
        </select> 
    </form>
    I think...
    arggghh..this didn't work either..it doesn't seem that this function forces the page to reload..

    @ Lil|aaron

    I tried yours and it didn't work either...


    this is an unexpected tricky issue...

  8. #8
    Join Date
    Jan 2009
    Posts
    3,346
    Code:
    <form id="cityform" action="" method="post">
        <select name="user_city" onchange="document.getElementById('cityform').submit()" >
              <option value="atlanta">Atlanta, GA</option>
              <option value="chicago">Chicago, Il</option>
        </select> 
    </form>

  9. #9
    Join Date
    Sep 2008
    Posts
    260
    Quote Originally Posted by criterion9 View Post
    Code:
    <form id="cityform" action="" method="post">
        <select name="user_city" onchange="document.getElementById('cityform').submit()" >
              <option value="atlanta">Atlanta, GA</option>
              <option value="chicago">Chicago, Il</option>
        </select> 
    </form>

    EXCELLENT!!

    This part worked and then the rest of my code was coded well and worked also...thanks!

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