469,342 Members | 6,942 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,342 developers. It's quick & easy.

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(),

Expand|Select|Wrap|Line Numbers
  1. <script language="JavaScript">
  2.  
  3. function autoSubmit()
  4. {
  5.     var formObject = document.forms['theForm'];
  6.     formObject.submit();
  7. }
  8.  
  9. </script>
  10.  
  11. <form name="theForm" method="post">
  12.  
  13. <?
  14. $code_query = "select customer_code from customer";
  15. $result = mysql_query($code_query);
  16. ?>
  17.  
  18. <select name= "combo_customer_code" OnChange="autoSubmit();"  >
  19. <option size =50 </option>
  20.  
  21. <?
  22. while($nt=mysql_fetch_array($result)){
  23. $code = $nt['customer_code'];
  24. echo '<option value="' .$nt['customer_code']. '">'. $nt['customer_code']. '</option>';
  25. }
  26. ?>
Dec 17 '09 #1
12 4992
zorgi
431 Expert 256MB
Expand|Select|Wrap|Line Numbers
  1. <option size =50 </option>
should probably be
Expand|Select|Wrap|Line Numbers
  1. <option size = "50"> 50 </option>
Also I don't see you closing <select></select>
Dec 17 '09 #2
Dormilich
8,651 Expert Mod 8TB
Expand|Select|Wrap|Line Numbers
  1. <option size = "50"> 50 </option>
invalid, the size attribute belongs to the select element. valid attributes for <option> are: disabled, selected, label, value.
Dec 17 '09 #3
zorgi
431 Expert 256MB
ooops :)

ment it like this:
Expand|Select|Wrap|Line Numbers
  1. <option value = "50"> 50 </option>
  2.  
Apologies
Dec 17 '09 #4
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.
Dec 18 '09 #5
Dormilich
8,651 Expert Mod 8TB
what do you mean by “sticky”?
Dec 18 '09 #6
kovik
1,044 Expert 1GB
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.
Expand|Select|Wrap|Line Numbers
  1. <select>
  2. <option value="X">Not selected</option>
  3. <option value="X" selected>This is selected</option>
  4. <!-- XML: <option value="X" selected="selected">This is selected</option> -->
  5. <option value="X">Not selected</option>
  6. </select>
Dec 18 '09 #7
Dormilich
8,651 Expert Mod 8TB
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.
Expand|Select|Wrap|Line Numbers
  1. <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.
Dec 18 '09 #8
kovik
1,044 Expert 1GB
Note that in order to use it, XML standards require that you make the value the name of the attribute.
Fixed. :3
Dec 18 '09 #9
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.
Dec 18 '09 #10
kovik
1,044 Expert 1GB
Then I have already given you the solution that you are looking for. Use the "selected" attribute to select an <option>.
Dec 18 '09 #11
zorgi
431 Expert 256MB
This could help you with the logic:

http://www.dmcinsights.com/phorum/re...?9,15643,15661
Dec 18 '09 #12
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
Dec 20 '09 #13

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

1 post views Thread by Dan | last post: by
2 posts views Thread by Yoshitha | last post: by
1 post views Thread by pmelanso | last post: by
7 posts views Thread by callawayglfr | last post: by
4 posts views Thread by TycoonUK | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
1 post views Thread by Marylou17 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.