Select value doesn`t work

Discussion in 'HTML' started by Kamyk, Feb 12, 2005.

  1. Kamyk

    Kamyk Guest

    Here are the fragment of my code:

    $ZAWARTOSC.="<form align=\"center\"

    action=\"_panel_administracyjny1.php?typ=menu_aktualizacja&rodzaj_operacji=a
    ktualizacja_dania&typ_dania=$menu_danie_typ&danie=$menu_danie&kos

    zt=$menu_danie_koszt&porcja=$menu_danie_porcja\" method=\"post\"
    name=\"formWprowadzMenu\" id=\"formWprowadzMenu\">
    <TR>
    <TD ALIGN=\"RIGHT\" class=\"a\"><FONT SIZE=\"2\" FACE=\"Verdana,Arial\">
    <select name=\"menu_danie_typ\"
    VALUE=\"".$adminlista[$liczba_w_bazie]["TYP_DANIA"]."\"
    id=\"menu_danie_typ\" size=\"1\">
    <option value=\"Chlopskie Jadlo\">Ch³opskie Jad³o</option>
    <option value=\"Zupy\">Zupy</option>
    <option value=\"Zakaski\">Zak?ski</option>
    <option value=\"Dania miesne\">Dania miêsne</option>
    <option value=\"Dziczyzna\">Dziczyzna</option>
    <option value=\"Dania z ryb\">Dania z ryb</option>
    <option value=\"Surowki\">Surówki</option>
    <option value=\"Dodatki\">Dodatki</option>
    <option value=\"Desery\">Desery</option>
    <option value=\"Napoje gorace\">Napoje gor?ce</option>
    <option value=\"Napoje\">Napoje</option>
    <option value=\"Soki\">Soki</option>
    <option value=\"Piwo\">Piwo</option>
    <option value=\"Koniaki i brandy\">Koniaki i brandy</option>
    <option value=\"Wodki\">Wódki</option>
    <option value=\"Whisky\">Whisky</option>
    <option value=\"Drinki\">Drinki</option>
    <option value=\"Wina\">Wina</option>
    <option value=\"Na zamowienie (z 48 godz. wyprzedzeniem)\">Na zamówienie
    (z 48 godz. wyprzedzeniem)</option>
    </select></font></td>


    <TD ALIGN=\"RIGHT\" class=\"a\"><FONT SIZE=\"2\" FACE=\"Verdana,Arial\">
    <input name=\"menu_danie\" type=\"text\" id=\"menu_danie\"
    value=\"".$adminlista[$liczba_w_bazie]["DANIE"]."\"
    size=\"30\"><BR></font></td>

    <TD ALIGN=\"RIGHT\" class=\"a\" WIDTH=\"1\"><FONT SIZE=\"2\"
    FACE=\"Verdana,Arial\">
    <input name=\"menu_danie_koszt\" type=\"text\" id=\"menu_danie_koszt\"
    value=\"".$adminlista[$liczba_w_bazie]["KOSZT"]."\"

    size=\"3\"><BR></font></td>

    <TD ALIGN=\"RIGHT\" class=\"a\" WIDTH=\"1\"><FONT SIZE=\"2\"
    FACE=\"Verdana,Arial\">
    <input name=\"menu_danie_porcja\" type=\"text\" id=\"menu_danie_porcja\"

    value=".$adminlista[$liczba_w_bazie]["PORCJA"].$zmienna_tymczasowa."
    size=\"3\"><BR></font></td>

    <TD ALIGN=\"RIGHT\" class=\"a\" WIDTH=\"1\"><FONT SIZE=\"2\"
    FACE=\"Verdana,Arial\">
    <input type=\"submit\" name=\"Submit\" value=\"Aktualizuj danie\"
    size=\"6\"></font></td>

    </TR>
    </FONT></form>";



    I used PHP language which is going a few times and show me the list of
    products from mysql database.
    I don`t know why IE doesn`t show me the actual status of "TYP_DANIA" and he
    shows me the first row of the list
    that is Chlopskie Jadlo as each of the whole list. It is mistake, because I
    have different types of "TYP_DANIA"
    saved in database. How to set the actual type of "TYP_DANIA" received from
    database in SELECT OPTION field
    and not a first type of the SELECT OPTION field?

    Please help me
    I would be very grateful for it
    Marcin from Poland
     
    Kamyk, Feb 12, 2005
    #1
    1. Advertising

  2. Kamyk wrote:
    > Here are the fragment of my code:
    >
    > <snip long, irrelevant PHP code>


    The PHP code doesn't matter. Give us a URL to the page so that we can
    see the HTML it generates.
     
    Leif K-Brooks, Feb 12, 2005
    #2
    1. Advertising

  3. Kamyk

    Kamyk Guest

    Kamyk, Feb 12, 2005
    #3
  4. Kamyk

    Kamyk Guest

    Kamyk, Feb 12, 2005
    #4
  5. Kamyk

    Jan Faerber Guest

    Leif K-Brooks ... output:

    > Kamyk wrote:
    >> Here are the fragment of my code:
    >>
    >> <snip long, irrelevant PHP code>

    >
    > The PHP code doesn't matter. Give us a URL to the page so that we can
    > see the HTML it generates.


    He just wants to have a form with a <select> list.
    Neither he wants to use the attribute 'selected' nor to select the first
    <option> element by default but he wants to select it according to a value
    from a mysql database.

    <select name=\"menu_danie_typ\"
    VALUE=\"".$adminlista[$liczba_w_bazie]["TYP_DANIA"]."\"
    id=\"menu_danie_typ\" size=\"1\">

    This sign '\' is just an escape sequence for the following special
    character. And this sign '.' is something like '+' in javascript:

    [...]
    '<p>Job Name: ' + form1.job.name.value + '</p><br />,
    [...]

    Try it with a javascript where you use:
    document.formWprowadzMenu.menu_danie_typ.options.selected=true;
    .... and must be the index ... or can you use
    ....options.value.name.selected???



    --
    Jan Faerber

    http://html.janfaerber.com
     
    Jan Faerber, Feb 12, 2005
    #5
  6. Kamyk

    Kamyk Guest

    > He just wants to have a form with a <select> list.
    > Neither he wants to use the attribute 'selected' nor to select the first
    > <option> element by default but he wants to select it according to a value
    > from a mysql database.
    >
    > <select name=\"menu_danie_typ\"
    > VALUE=\"".$adminlista[$liczba_w_bazie]["TYP_DANIA"]."\"
    > id=\"menu_danie_typ\" size=\"1\">
    >
    > This sign '\' is just an escape sequence for the following special
    > character. And this sign '.' is something like '+' in javascript:
    >
    > [...]
    > '<p>Job Name: ' + form1.job.name.value + '</p><br />,
    > [...]
    >
    > Try it with a javascript where you use:
    > document.formWprowadzMenu.menu_danie_typ.options.selected=true;
    > ... and must be the index ... or can you use
    > ...options.value.name.selected???
    >


    Could you explain me with more details and write to me the whole example of
    usage this JavaScript code.
    Unfortunately I am not good at JavaScript. I have tried to do myself, but
    without a
    good result.

    Thank you in advance
    Marcin
     
    Kamyk, Feb 13, 2005
    #6
  7. Kamyk

    Jan Faerber Guest

    Kamyk ... output:

    >> He just wants to have a form with a <select> list.
    >> Neither he wants to use the attribute 'selected' nor to select the first
    >> <option> element by default but he wants to select it according to a
    >> value from a mysql database.


    $ZAWARTOSC.="<form [...] name=\"formWprowadzMenu\">
    <select name=\"menu_danie_typ\" size=1>
    <option value=\"Chlopskie Jadlo\">Ch³opskie Jad³o</option>
    <option value=\"Zupy\">Zupy</option>
    [...]
    <option value=\"Wina\">Wina</option>
    <option value=\"Na zamowienie (z 48 godz. wyprzedzeniem)\">Na zamówienie
    (z 48 godz. wyprzedzeniem)</option>
    </select>
    [...]

    Here is the ...select... element of the form you want to store in the php
    varible $ZAWARTOSC. (with a full stop in the end?)
    You can preselect e.g. the ...option... 'Whisky' by using
    <option value=\"Whisky\" selected>Whisky</option> but you don't do this by
    an attribute of the ...select... tag!

    So - you don't know in advance which element has to be selected. You want to
    use php to find it out in your database.


    > Could you explain me with more details and write to me the whole example
    > of usage this JavaScript code.
    > Unfortunately I am not good at JavaScript. I have tried to do myself, but
    > without a
    > good result.
    >
    > Thank you in advance
    > Marcin



    <html><head><title>ZAWARTOSC.</title>
    <script language="JavaScript" type="text/javascript">
    <!--
    function preselect()
    {
    for(i=0; i<document.formWprowadzMenu.menu_danie_typ.length; i++)

    <?php
    echo "if(document.formWprowadzMenu.menu_danie_typ.options.text =
    \"".$adminlista[$liczba_w_bazie]["TYP_DANIA"]."\"
    ?>

    document.formWprowadzMenu.menu_danie_typ.options.selected=true;
    }
    //-->
    </script>

    </head><body onLoad="preselect()">

    [...]

    <?php
    echo $ZAWARTOSC.
    ?>

    [...]</body></html>




    --
    Jan Faerber

    http://html.janfaerber.com
     
    Jan Faerber, Feb 14, 2005
    #7
  8. Kamyk

    Jan Faerber Guest

    [important!!!] Re: Select value doesn`t work

    Jan Faerber ... output:


    > <?php
    > echo "if(document.formWprowadzMenu.menu_danie_typ.options.text =
    > \"".$adminlista[$liczba_w_bazie]["TYP_DANIA"]."\"
    > ?>



    sorry - in the if(..) you have to use '==' !!!!! ... but I haven't tested
    this with mysql. And the closing ')' was missing in my script!! ... so it
    is
    bla, bla, bla... ["TYP_DANIA"]."\") - ok? Something else is missing? Check
    it carefully if anything doesn't work.



    Best wishes



    --
    Jan

    http://html.janfaerber.com
     
    Jan Faerber, Feb 14, 2005
    #8
  9. Kamyk

    Kamyk Guest

    I have tried to implement your code into my page, but it doesn`t work all
    the time.
    Here is my whole code (sorry for that, but without you I would do nothing):



    <HTML>
    <HEAD>
    <HEAD>
    <META HTTP-EQUIV="Content-type" CONTENT="text/html; charset=iso-8859-2">
    <META NAME="Keywords" CONTENT="kuchnia polska, dzik, pieczeñ, ¿urek">
    <META NAME="Description" CONTENT="Karczma Polska - kuchnia staropolska to
    nasza specjlano¶æ">
    <META NAME="Author" CONTENT="bk j'aime bien zorro">
    <TITLE>Karczma Polska - Bydgoszcz</TITLE>
    <LINK REL="stylesheet" HREF="karczma.css" TYPE="text/css">



    <SCRIPT LANGUAGE="JavaScript" TYPE="TEXT/JAVASCRIPT">
    <!-- Ukrycie skryptu przed starszymi przegl±darkami

    function preselect()
    {
    for(i=0; i<document.formWprowadzMenu.menu_danie_typ.length; i++)

    <?php
    echo "if(document.formWprowadzMenu.menu_danie_typ.options.text ==
    \"".$adminlista[$liczba_w_bazie]["TYP_DANIA"]."\")"
    ?>

    document.formWprowadzMenu.menu_danie_typ.options.selected=true;
    }


    // Koniec ukrywania przed starszymi przegl±darkami -->
    </SCRIPT>



    </HEAD>
    <BODY BGCOLOR="#FFFFCC" TEXT="#004000" LINK="#7F0000" ALINK="#FF0000"
    VLINK="#7F0000" onLoad="preselect()">
    <CENTER>
    <FONT SIZE="2" FACE="Verdana,Arial" COLOR="#7F0000">
    <B>Panel administracyjny</B>
    </FONT><BR>
    <HR SIZE="1" WIDTH="100%">
    <?

    $ZAWARTOSC="";



    if ($typ=="menu")
    {

    $ZAWARTOSC.="<TABLE WIDTH=\"500\" CELLSPACING=\"2\" CELLPADDING=\"1\"
    BORDER=\"0\">

    <TR>
    <TD HEIGHT=\"50\">&nbsp;</TD>
    </TR>

    <TR>
    <TH class=\"c\" COLSPAN=\"2\" ALIGN=\"CENTER\"><FONT SIZE=\"2\"
    FACE=\"Verdana,Arial\">Aktualizuj menu</A></FONT></th>
    </tr>

    <TR>
    <TD HEIGHT=\"30\">&nbsp;</TD>
    </TR>

    <TR>
    <TH class=\"c\" COLSPAN=\"2\">
    <FONT SIZE=\"2\" FACE=\"Verdana,Arial\"><A
    HREF=\"_panel_administracyjny1.php?typ=menu_aktualizacja\"><U> Menu -
    aktualizacja </U></A>
    </FONT>
    </th>
    </tr>

    <TR>
    <TD HEIGHT=\"30\">&nbsp;</TD>
    </TR>


    <TR>
    <TH class=\"c\" COLSPAN=\"2\">
    <FONT SIZE=\"2\" FACE=\"Verdana,Arial\"><A
    HREF=\"_panel_administracyjny1.php?typ=menu_nowe_dania\"><U> Menu -
    dodawanie nowych dañ </U></A>
    </FONT>
    </th>
    </tr>

    </TABLE>";

    }




    if ($typ=="menu_aktualizacja")
    {

    $link = mysql_connect("mysql.telvinet.pl", "karczma", "tadeusz") or die
    ("Serwer die");
    mysql_select_db ("karczma") or die ("Baza die");
    $db_name="karczma";
    $query = "SELECT * FROM menu";
    $result = mysql_db_query ($db_name, $query);
    $liczba_w_bazie = 1;


    $ZAWARTOSC.="<TABLE WIDTH=\"500\" CELLSPACING=\"2\" CELLPADDING=\"1\"
    BORDER=\"0\">
    <TR>
    <TH class=\"c\" COLSPAN=\"2\"><FONT SIZE=\"2\"
    FACE=\"Verdana,Arial\">Aktualizuj menu</A></FONT></th>
    </tr>
    <tr></tr>
    <tr>
    <TH class=\"b\" ><FONT SIZE=\"2\" FACE=\"Verdana,Arial\">TYP
    DANIA</A></FONT></th>
    <TH class=\"b\"><FONT SIZE=\"2\"
    FACE=\"Verdana,Arial\">DANIE</A></FONT></th>
    <TH class=\"b\"><FONT SIZE=\"2\"
    FACE=\"Verdana,Arial\">KOSZT</A></FONT></th>
    <TH class=\"b\"><FONT SIZE=\"2\"
    FACE=\"Verdana,Arial\">PORCJA</A></FONT></th>
    </tr>
    ";

    while ($offdata = mysql_fetch_array ($result))
    {
    $adminlista[$liczba_w_bazie]["DANIE"] = $offdata[0];
    $adminlista[$liczba_w_bazie]["KOSZT"] = $offdata[1];
    $adminlista[$liczba_w_bazie]["PORCJA"] = $offdata[2];
    $adminlista[$liczba_w_bazie]["TYP_DANIA"] = $offdata[3];

    $zmienna_tymczasowa=($adminlista[$liczba_w_bazie]["PORCJA"]>4)?" ml.":"
    szt.";

    $ZAWARTOSC.="<form align=\"center\"

    action=\"_panel_administracyjny1.php?typ=menu_aktualizacja&rodzaj_operacji=a
    ktualizacja_dania&typ_dania=$menu_danie_typ&danie=$menu_danie&kos

    zt=$menu_danie_koszt&porcja=$menu_danie_porcja\" method=\"post\"
    name=\"formWprowadzMenu\" id=\"formWprowadzMenu\">
    <TR>
    <TD ALIGN=\"RIGHT\" class=\"a\"><FONT SIZE=\"2\" FACE=\"Verdana,Arial\">
    <select name=\"menu_danie_typ\" id=\"menu_danie_typ\" size=\"1\">
    <option value=\"Chlopskie Jadlo\">Ch³opskie Jad³o</option>
    <option value=\"Zupy\">Zupy</option>
    <option value=\"Zakaski\">Zak?ski</option>
    <option value=\"Dania miesne\">Dania miêsne</option>
    <option value=\"Dziczyzna\">Dziczyzna</option>
    <option value=\"Dania z ryb\">Dania z ryb</option>
    <option value=\"Surowki\">Surówki</option>
    <option value=\"Dodatki\">Dodatki</option>
    <option value=\"Desery\">Desery</option>
    <option value=\"Napoje gorace\">Napoje gor?ce</option>
    <option value=\"Napoje\">Napoje</option>
    <option value=\"Soki\">Soki</option>
    <option value=\"Piwo\">Piwo</option>
    <option value=\"Koniaki i brandy\">Koniaki i brandy</option>
    <option value=\"Wodki\">Wódki</option>
    <option value=\"Whisky\">Whisky</option>
    <option value=\"Drinki\">Drinki</option>
    <option value=\"Wina\">Wina</option>
    <option value=\"Na zamowienie (z 48 godz. wyprzedzeniem)\">Na zamówienie
    (z 48 godz. wyprzedzeniem)</option>
    </select></font></td>


    <TD ALIGN=\"RIGHT\" class=\"a\"><FONT SIZE=\"2\" FACE=\"Verdana,Arial\">
    <input name=\"menu_danie\" type=\"text\" id=\"menu_danie\"
    value=\"".$adminlista[$liczba_w_bazie]["DANIE"]."\"
    size=\"30\"><BR></font></td>

    <TD ALIGN=\"RIGHT\" class=\"a\" WIDTH=\"1\"><FONT SIZE=\"2\"
    FACE=\"Verdana,Arial\">
    <input name=\"menu_danie_koszt\" type=\"text\" id=\"menu_danie_koszt\"
    value=\"".$adminlista[$liczba_w_bazie]["KOSZT"]."\"

    size=\"3\"><BR></font></td>

    <TD ALIGN=\"RIGHT\" class=\"a\" WIDTH=\"1\"><FONT SIZE=\"2\"
    FACE=\"Verdana,Arial\">
    <input name=\"menu_danie_porcja\" type=\"text\" id=\"menu_danie_porcja\"

    value=".$adminlista[$liczba_w_bazie]["PORCJA"].$zmienna_tymczasowa."
    size=\"3\"><BR></font></td>

    <TD ALIGN=\"RIGHT\" class=\"a\" WIDTH=\"1\"><FONT SIZE=\"2\"
    FACE=\"Verdana,Arial\">
    <input type=\"submit\" name=\"Submit\" value=\"Aktualizuj danie\"
    size=\"6\">

    </font></td>

    </TR>
    </FONT></form>";


    }

    $ZAWARTOSC.="</TABLE>";


    }

    print ( $ZAWARTOSC );

    ?>
     
    Kamyk, Feb 14, 2005
    #9
  10. Kamyk

    Jan Faerber Guest

    Kamyk ... output:

    > I have tried to implement your code into my page, but it doesn`t work all
    > the time.
    > Here is my whole code (sorry for that, but without you I would do
    > nothing):


    Here is my database:
    http://html.janfaerber.com/php/zawar/list2.php
    Here is the script for this:
    http://html.janfaerber.com/php/zawar/list2.php.txt

    I use that here aswell on the top of the page:
    http://html.janfaerber.com/php/zawar/beer.lsd
    .... and below I put the form ... I did the javascript in the body now.
    Here is the script for this:
    http://html.janfaerber.com/php/zawar/beer.lsd.txt



    --
    Jan

    http://html.janfaerber.com
     
    Jan Faerber, Feb 15, 2005
    #10
  11. Kamyk

    Kamyk Guest

    Uzytkownik "Jan Faerber" <> napisal w
    wiadomosci news:UJqQd.49418$...
    > Kamyk ... output:
    >
    > > I have tried to implement your code into my page, but it doesn`t work

    all
    > > the time.
    > > Here is my whole code (sorry for that, but without you I would do
    > > nothing):

    >
    > Here is my database:
    > http://html.janfaerber.com/php/zawar/list2.php
    > Here is the script for this:
    > http://html.janfaerber.com/php/zawar/list2.php.txt
    >
    > I use that here aswell on the top of the page:
    > http://html.janfaerber.com/php/zawar/beer.lsd
    > ... and below I put the form ... I did the javascript in the body now.
    > Here is the script for this:
    > http://html.janfaerber.com/php/zawar/beer.lsd.txt
    >
    >
    >
    > --
    > Jan
    >
    > http://html.janfaerber.com



    Thank you a lot for such help.
    Today I cannot check this code.
    I will do it tomorrow in the evening.
    Thank you again Jan - you are great.
    Marcin from Poland
     
    Kamyk, Feb 15, 2005
    #11
  12. Kamyk

    Kamyk Guest

    Thank you a lot

    Best regards
    Marcin
     
    Kamyk, Feb 16, 2005
    #12
  13. Kamyk

    Jan Faerber Guest

    Kamyk ... output:

    > Thank you a lot
    >
    > Best regards
    > Marcin


    Hello Marcin - today I tried to look at the source files of my two .txt
    links above. I was not able to see the text as I wrote it in an editor!!!
    Huch! Why that? I can see it correctly on my local machine were the web
    server is running but not from outside on WinXP. Good to know that!

    So I have made a zip file now
    http://html.janfaerber.com/php/zawar/select.zip

    Download this one and decompress it with winzip or another unzip utility.




    --
    Jan

    http://html.janfaerber.com
     
    Jan Faerber, Feb 17, 2005
    #13
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Kamyk
    Replies:
    4
    Views:
    1,326
    Jan Faerber
    Feb 15, 2005
  2. Pavans
    Replies:
    1
    Views:
    643
    Brock Allen
    May 6, 2006
  3. dada
    Replies:
    0
    Views:
    162
  4. Nicolae Fieraru
    Replies:
    3
    Views:
    115
    Aaron Bertrand - MVP
    Jul 17, 2003
  5. palmiere
    Replies:
    1
    Views:
    465
    Erwin Moller
    Feb 9, 2004
Loading...

Share This Page