Link to home
Start Free TrialLog in
Avatar of Eduardo Fuerte
Eduardo FuerteFlag for Brazil

asked on

How to make the combo assume previous selected option code ?

Hi Experts!

If a combo starts with a marked option how to make the selected option code (sb_cccx in the example) to assume the initial value correspondent to the option selected despite the fact the user access the combo or not?

             <tr>
      		 <td>
                 CC/ Cx:
                 <select name="sb_cccx">
                 <option value="<?php echo $d_cccx;?>" selected> <?php  echo $d_cccx;?></option>   
                    </option>
                    
                     <?php

    //----------Inicio Combo 1 (CCCX) -----------------------------------------------------------------
    $sql = mysql_query("select sb_cccx, cx_info, substr(descricao,1,25) as descricao from cccx where ativa=1 order by descricao");
    //----------Final Combo 1-------------------------------------------------------------------------

    while ($row = mysql_fetch_array($sql)) {
        $id = $row['sb_cccx'];
        $data = $row['descricao'];
        echo '<option value="' . $id . '">' . $data . '</option>';
    }

?>
            </select>
            </td>                
            </tr>    

Open in new window


Thanks in advance!
Avatar of Ray Paseur
Ray Paseur
Flag of United States of America image

If I'm understanding your question correctly, it will do exactly what you want.  If you can post a link to the HTML document that is generated by this PHP code, I'll be glad to investigate further.
Avatar of Chris Stanyon
Didn't we answer this question earlier? Have a re-read through your previous question.

If you need the combo to have a previously selected option SELECTed then the answer was previously posted (by the two people whose answer you didn't accept...)
@ChrisStanyon: Yes, I think the answer is already there in the other question -- in one form or another.  The understanding might be as simple as running the script, looking at the generated HTML document and using var_dump($_REQUEST) in the action script.
Avatar of Eduardo Fuerte

ASKER

Hello

ChrisStanyon
The question is similar and could cause confusion but it's different if you pay attention is easy to note, by the way your last reply didn´t work in my tests.

Ray
Send you the html like I did  days ago to receive the same tests at W3C validator proved to be unproductive. Would you like it again to the same purposes?
@EFuerte - sorry - I'm not entirely sure what you want. If you want to select an option then you simply add 'selected' to it:

<select name="sb_cccx">
     <option value"something" selected>This is selected</option>
     .....
</select>

Open in new window

If you want to select a previously selected option then you need code to check each option against the previously selected option.
I guess I do not understand the question.  I do not see anything wrong with your code, but I do not have any test data to work with, so it's unlikely that you can trust my vision.  Can you please show us the SSCCE that illustrates the issue?
Ok, using pictures.

1. Say the user needs to edit a register to change something, choose and ask to edit:
User generated image
 2. So he changes one of the combos
User generated image
3. And doesn´t touch the others combos
User generated image
4. So he try to saves it to BD.
User generated image
The combo the user has changed receive the correct code but the others received  incorrect "literal" codes. What I need is a way to store the previous code sent to the edit form for all the controls (touched or not) to permit a correct update then.

Hope clarify.
The SQL error probably occurs because the open paren before ,4,100,CONDOMNIO... has a leading blank but no value before the comma.

I don't really know how to answer your question.  Getting data from an HTML form into a PHP script is accomplished with the patterns shown in this tutorial.  Getting data from the PHP script into the MySQL data base is taught in this book.  Maybe you can store this information in an active record, or perhaps you can store it in the PHP session array.
The sql string is not the focus and irrelevant by now, it will be correctly treated after I had the correct values received, where you've read CONDOMINIO it would be a numerical code from the combo, instead, not the literal from the combo.

But after more thinking it's a matter of check if the value received for the update is literal or numerical and in case of not being numeric, simple don't use it in update, since it's a symptom of not changed value...
ASKER CERTIFIED SOLUTION
Avatar of Ray Paseur
Ray Paseur
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Ray

(Maybe you're celebrating Independence Day 4th July, if so, congratulations!)

Unfortunatelly no.

I need a way to associate a numerical code  corresponding to every combo based on an existing BD register when the form charges.

If someone decides to edit  existing information and don't change some of the combos, the code informations of this combos must be what the form received at the start, otherwise it incorrectly sends litteral values.

I hope it clarifies.
Sorry, I just don't get it. If you can create examples that show the before and after conditions maybe we can help.
Hello

I've just treated the combo's reply used to insertion in DB, if it's literal it's a matter of find the correspondent code in a query. If it's numeric it's just ok to insertion in the correspondente column.