![]() |
|
#1
|
|||
|
|||
combo box select problemhi,
i am getting value of project from database PHP Code:
let say the value for project combo box is Apple,Mango so when i select mango from project field and then submit the form i will get mango as printed value,i want mango must be shown selected in new line,whatever i select it will be shown as selectd on next new line,but in my case always Apple as selected in new line let say in my list 1.Dad 2.Mom 3.Didi //if i select didi from this field then new line should be didi 4.Uncle as selected 5.Aunty but above code always shown as Dad selected, how i cna get selected item as shown in new line thanks |
|||
|
#2
|
||||
|
||||
|
Hello zuzupus,
Seriously, I had a really hard time understanding your question, can you try re-phrasing it? Or maybe a sample page to view? __________________
J de Silva Learning Journal | GIDForums™ | GIDNetwork™ | GIDWebhosts™ | GIDSearch™ |
|
#3
|
|||
|
|||
|
zuzupus,
I went through the same dilemna about a month ago--there's a simple fix. What's happening is that your HTML select box needs the options to have PHP code to write the word 'selected' in order to capture the sumbitted value, otherwise your code will continue to ignore the sumitted value and write the HTML for a drop-down box without any one option explicitly selected. The default submission value of an unselected drop-down box is its first value, in your case 'Dad'. If you wanted to have Didi selected when you write your page after submission, the HTML code should look like this: <select name="projekt"> <option></option> <option value="Dad">Dad</option> <option value="Mom">Mom</option> <option value="Didi" selected>Didi</option> <option value="Uncle">Uncle</option> <option value="Aunty">Aunty</option> </select> Note: Adding the first empty option tag will make your drop-down box show an empty entry as the default. In order to store the sumitted combo box value in a variable ($name), you can set it equal to the value posted under the combo box's name. Put this code up before your combo box, wherever you initialize variables. If your page is being visited (initially) before the form has been submitted, the variable ($name) with not contain a value. <?php $name = $_POST['projekt']; ?> <select name="projekt"> <option></option> <option value="Dad" <?php if ($name=="Dad") {echo "selected";}?>>Dad</option> <option value="Mom" <?php if ($name=="Mom") {echo "selected";}?>>Mom</option> <option value="Didi" <?php if ($name=="Didi") {echo "selected";}?>>Didi</option> <option value="Uncle" <?php if ($name=="Uncle") {echo "selected";}?>>Uncle</option> <option value="Aunty" <?php if ($name=="Aunty") {echo "selected";}?>>Aunty</option> </select> So change your code to incorporat this logic: ======================= <? $name = $_POST['projekt']; ?> ....... <select name="projekt"> <option></option> <? foreach($hprojekt as $value) { ?> <option value="<?= $value" if ($name==$value) {echo "selected";} ?>"><?= $value ?></option> <? } ?> </select> ======================= Good luck! samtediou |
Recent GIDBlog
Once again, no time for hobbies by crystalattice
| Thread Tools | Search this Thread |
| Rate This Thread | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| editable combo box | zuzupus | Web Design Forum | 4 | 13-Dec-2005 16:01 |
| unwanted scrollbar problem | kelly001 | Web Design Forum | 3 | 24-Oct-2003 11:44 |
| select problem | zuzupus | MySQL / PHP Forum | 0 | 15-Aug-2003 08:25 |
| join problem | zuzupus | MySQL / PHP Forum | 0 | 14-Aug-2003 06:11 |
| client side problem | zuzupus | MySQL / PHP Forum | 2 | 22-Jul-2003 07:47 |
Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The