drop down sticky in php

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • manuitpro
    New Member
    • Dec 2009
    • 13

    drop down sticky in php

    I am trying to make drop down stick in my php. Below is my code, can some one help me to make it sticky. I am tried and lost. I have two dropdown in the form, each pulls data from mysql with condition OnChange(),

    Code:
    <script language="JavaScript">
    
    function autoSubmit()
    {
        var formObject = document.forms['theForm'];
        formObject.submit();
    }
    
    </script>
    
    <form name="theForm" method="post">
    
    <?
    $code_query = "select customer_code from customer";
    $result = mysql_query($code_query);
    ?>
    
    <select name= "combo_customer_code" OnChange="autoSubmit();"  >
    <option size =50 </option>
    
    <?
    while($nt=mysql_fetch_array($result)){
    $code = $nt['customer_code'];
    echo '<option value="' .$nt['customer_code']. '">'. $nt['customer_code']. '</option>';
    }
    ?>
    Last edited by Dormilich; Dec 17 '09, 11:58 AM. Reason: Please use [code] tags when posting code
  • zorgi
    Recognized Expert Contributor
    • Mar 2008
    • 431

    #2
    Code:
    <option size =50 </option>
    should probably be
    Code:
    <option size = "50"> 50 </option>
    Also I don't see you closing <select></select>

    Comment

    • Dormilich
      Recognized Expert Expert
      • Aug 2008
      • 8694

      #3
      Code:
      <option size = "50"> 50 </option>
      invalid, the size attribute belongs to the select element. valid attributes for <option> are: disabled, selected, label, value.

      Comment

      • zorgi
        Recognized Expert Contributor
        • Mar 2008
        • 431

        #4
        ooops :)

        ment it like this:
        Code:
        <option value = "50"> 50 </option>
        Apologies

        Comment

        • manuitpro
          New Member
          • Dec 2009
          • 13

          #5
          I am not concerned about the size of the drop down, my concern is to make the drop down stick, </select> is there in my coding, i have put only part the code in the forum. Can u please comment on how to make my drop down sticky.

          Comment

          • Dormilich
            Recognized Expert Expert
            • Aug 2008
            • 8694

            #6
            what do you mean by “sticky”?

            Comment

            • kovik
              Recognized Expert Top Contributor
              • Jun 2007
              • 1044

              #7
              Sticky as in...?

              Normally, sticky dropdowns refer to keeping the last selection as the current selection when the form is unsuccessfully submitted due to errors. Is this what you are after?

              If so, make use of the "selected" attribute of the <option> elements. Note that in order to use it with XML/XHTML, W3C standards require that you make the value the name of the attribute.
              Code:
              <select>
              <option value="X">Not selected</option>
              <option value="X" selected>This is selected</option>
              <!-- XML: <option value="X" selected="selected">This is selected</option> -->
              <option value="X">Not selected</option>
              </select>
              Last edited by Dormilich; Dec 18 '09, 02:03 PM. Reason: see posts below

              Comment

              • Dormilich
                Recognized Expert Expert
                • Aug 2008
                • 8694

                #8
                Note that in order to use it, W3C standards require that you make the value the name of the attribute.
                incorrect, the HTML specs explicitly state the attribute to be standalone.
                Code:
                <option value="X" selected>This is selected</option>
                what you are talking about refers to the XHTML specs, where the attribute must be defined this way due to the XML specs. but since most people use XHTML as HTML (and not as XML), it doesn’t matter how you write it.

                Comment

                • kovik
                  Recognized Expert Top Contributor
                  • Jun 2007
                  • 1044

                  #9
                  Note that in order to use it, XML standards require that you make the value the name of the attribute.
                  Fixed. :3

                  Comment

                  • manuitpro
                    New Member
                    • Dec 2009
                    • 13

                    #10
                    Thanks for ur replies... Let me put it again
                    I have two dynamic drop down's, first one pulls records from mysql and when user selects a option the second poulates values based on the user selected option in first one. Now what happens when user selects option in first drop down the pages refreshes and its selection reset to blank. I want to show the selected option in the first drop down when onchange happens. I want to preserve the selected after submitting the page(on change()). Please check my code above.

                    Comment

                    • kovik
                      Recognized Expert Top Contributor
                      • Jun 2007
                      • 1044

                      #11
                      Then I have already given you the solution that you are looking for. Use the "selected" attribute to select an <option>.

                      Comment

                      • zorgi
                        Recognized Expert Contributor
                        • Mar 2008
                        • 431

                        #12
                        This could help you with the logic:

                        Comment

                        • manuitpro
                          New Member
                          • Dec 2009
                          • 13

                          #13
                          Thank you all the experts...
                          After refering your comments finally I managed to make sticky dropdown.

                          I would personally thanks Zorgi for posting his Logic page

                          Comment

                          Working...