| | |||||
| ||||||||
| Programming PHP, Perl, Ruby on Rails, AJAX, HTML, XHTML, CSS, JavaScript, MySQL and any other coding topics. |
![]() |
| | LinkBack | Thread Tools |
| | THREAD STARTER #1 (permalink) |
| Soon to be RICHdoggie! Join Date: Jan 2005 Location: UK
Posts: 2,408
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() | <select> "selected" auto-pick Sorry about the vagueness of the title, but I have a problem. I have a form that includes <select> boxes. Now when a user submits this form it goes to a php page where it either sends an email to me includng the values in the form, OR it reports an error to the user and display's the form again. Now, unlike normal text inputs (<input type="text">) the "value" attribute cannot be used here (as in <select value="<?php echo $hosting; ?>">) I assume. So is there an easy way to have the chosen option displayed automatically? ????: NamePros.com http://www.namepros.com/programming/99203-select-selected-auto-pick.html Normally you would put <option selected value="..">...</option>, but I hoped I didn't have to create php functions to output <select> boxes with the right option selected. Please say there is an easy way! I hope you understand! ![]() Thanks a lot Tom |
| |
| | #2 (permalink) |
| Senior Member Join Date: Jun 2003 Location: UK
Posts: 3,547
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() | I don't think there's any other way other than using "selected" unless you use javascript to go back, which might work. <html> <head> <title>Go back!</title> </head> <body onload="javascript:history.go(-1)"> <script language="Javascript"> <!-- alert("Error message...blah blah blah. Press OK to go back."); //--> </script> </body> </html> Maybe? |
| |
| | #3 (permalink) |
| NamePros Regular Join Date: Oct 2003 Location: Sweden
Posts: 395
![]() ![]() | Either you put in an conditional clause at every option, or you store the option values in an array/db and loop through it with a conditional to write out selected. "selected" is THE way to mark an option as selected. |
| |
| | THREAD STARTER #5 (permalink) | ||||
| Soon to be RICHdoggie! Join Date: Jan 2005 Location: UK
Posts: 2,408
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() |
anyway - so I would have to do something like this: PHP Code: Thanks Tom | ||||
| |
| | #6 (permalink) |
| NamePros Member Join Date: Jun 2004
Posts: 92
![]() | slightly easier: PHP Code:
__________________ Bais Menachem |
| |
| | THREAD STARTER #7 (permalink) | ||||
| Soon to be RICHdoggie! Join Date: Jan 2005 Location: UK
Posts: 2,408
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() |
thanks! ![]() ![]() | ||||
| |
| | #8 (permalink) |
| NamePros Member Join Date: Apr 2005 Location: Boston, MA
Posts: 26
![]() | A little more easier to read version. If you want to add another option to the select you just add another value to the select_values array. PHP Code: |
| |
| | #9 (permalink) |
| NamePros Member Join Date: Jun 2005 Location: Indianapolis, IN
Posts: 61
![]() | Heh. Why not just use javascript validation? If there's an error on submit then alert the user, the page won't post and you won't have to refill any values. If it validates then it will goto the next page and send you an email.
__________________ Kupo? |
| |
| | #10 (permalink) | ||||
| NamePros Member Join Date: Jun 2004
Posts: 92
![]() |
i should've thought of that...
__________________ Bais Menachem | ||||
| |
![]() |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| |
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Auto resize flash with html in php | zander | Programming | 8 | 06-15-2005 12:40 PM |
| GTA / Grand Theft Auto network wants you! | Ringr | For Sale / Advertising Board | 0 | 05-17-2005 08:37 PM |
| Buying links from PR5+ auto / sports sites | mr-x | For Sale / Advertising Board | 0 | 01-17-2005 10:00 AM |