SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Member
    Join Date
    Feb 2008
    Posts
    3
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Changing Menus Dynamically

    Hi
    I am new to this forum. someone gave me a menu that changes the options of a second menu according to the first choice.
    It can be found at:
    http://www.students-solutions.com/lu...ubcate=&cajas=
    Now The code is the following:
    <?php

    mysql_connect("localhost","root","");
    mysql_select_db("datos");
    echo '<center><form name="find" method="post" action=""> Categoria';

    $sSQL="Select distinct cate From combo order by id";
    if(!($result=mysql_query($sSQL))){
    echo "error :".mysql_error();
    exit();}


    echo '<select name="cate" onChange="this.form.submit();"> ';
    $cate = $_POST['cate'];
    echo '<option>'; echo "$cate";

    while ($row=mysql_fetch_array($result)){
    echo "<option value=".$row["cate"]." >".$row["cate"];}
    echo '</select>';
    mysql_free_result($result);

    echo '<br>Sub Categoria';


    $sSQL2="Select * From combo where cate='$cate' order by id";

    if(!($result2=mysql_query($sSQL2))){
    echo "error :".mysql_error();
    exit();}
    echo '<select name="subcate" class="Estilo9" > ';
    echo '<option>';

    while ($row2=mysql_fetch_array($result2)){
    echo "<option value=".$row2["subcate"]." >".$row2["subcate"];}
    echo '</select>';
    mysql_free_result($result2);


    echo '<br>caja de texto <input type="text" name="cajas" size="10" class=cajaTexto value='.$cajas.'>';

    echo '<br><input type="submit" value="Enviar" name="B1"> </form>';

    if ($subcate<>"") {

    echo "se guardo los datos con exito";
    }

    else
    {


    }



    My question is what happens when someone chooses an option in the first menuor in other words Which line is executed after the
    onChange="this.form.submit();">

    detects that an option has been chosen in the first menu.


    please let me know


    thanks in advanced
    Luis

  2. #2
    SitePoint Enthusiast Boxer's Avatar
    Join Date
    Jan 2008
    Location
    Denver, Colorado
    Posts
    86
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    When next time you'll be posting code, please surround it with [PHP] and [/PHP] - it will be much easier to read it.

    When the first menu selection changes, the submit() method submits the form. It means that the browser passes values of cate, subcate and cajas fields to... as the form has no action value, data go to the same script, and get stored in variables $_POST['cate'], $_POST['subcate'] and $_POST['cajas']. The script runs from the first line to the last one, just like the previous time.
    Last edited by Boxer; Feb 9, 2008 at 14:07.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •