problems with dropdown menus

Discussion in 'Programming' started by Tehy, Oct 15, 2007.

  1. #1
    Hi,

    I have two Dropdown menus:

    <FORM NAME="myform1" action="phones.php">
    <SELECT NAME="mylist1" onChange="this.form.submit();">
    <OPTION VALUE="Null"></OPTION>
    <OPTION VALUE="S500i">Sony Ericsson S500i</OPTION>
    </SELECT>
    </FORM>
    
    <FORM NAME="myform2" action="phones.php">
    <SELECT NAME="mylist2" onChange="this.form.submit();">
    <OPTION VALUE="Null"></OPTION>
    <OPTION VALUE="S500i">Sony Ericsson M600i</OPTION>
    </SELECT>
    </FORM>
    HTML:
    So if I for example have phones.php:

    <FORM NAME="myform1" action="phones.php">
    <SELECT NAME="mylist1" onChange="this.form.submit();">
    <OPTION VALUE="Null"></OPTION>
    <OPTION VALUE="S500i">Sony Ericsson S500i</OPTION>
    </SELECT>
    </FORM>
    
    <FORM NAME="myform2" action="phones.php">
    <SELECT NAME="mylist2" onChange="this.form.submit();">
    <OPTION VALUE="Null"></OPTION>
    <OPTION VALUE="M600i">Sony Ericsson M600i</OPTION>
    </SELECT>
    </FORM>
    
    <?php
    echo $mylist1;
    echo $mylist2;
    ?>
    PHP:
    The problem is that when user for example chooses Sony Ericsson S500i from myform1... when the submit is done the myform1 shows the "Null" value, not the Sony Ericsson S500i. How to change this?

    Bigger problems is that when user first uses the myform1 and then the myform2, it doesn't remember the myform1 value. is there any way to submit those forms in the same time?

    Huh, I hope got it :) Anyone?
     
    Tehy, Oct 15, 2007 IP
  2. Lordy

    Lordy Peon

    Messages:
    1,643
    Likes Received:
    29
    Best Answers:
    0
    Trophy Points:
    0
    #2
    your php code is wrong.

    i think for action instead you could use <?=$_SERVER['PHP_SELF']?> not too sure how action="phones.php" is working for you.

    does the form show any values at all? i think it is because you are not grabbing values into your variables.

    how is $mylist1 and $mylist2 set? if you want to grab it off your form you will need to have
    $mylist1=$_POST['myform1']
    $mylist2=$_POST['myform2']
    PHP:
    assuming that it grabs from form name not select name? (not too sure)
     
    Lordy, Oct 16, 2007 IP
  3. Tehy

    Tehy Peon

    Messages:
    254
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Ok. Not sure if I made my self clear enought :p Try this:
    http://www.sefanatics.com/PUHELIN VERTAILU/index.php

    Choose from the list one Sony Ericsson S500i and then choose from the list two Sony Ericsson S500i. The problem is that it doesn't remember the values that are shown when you made the first choose (list one).

    The site isn't ready so there might be weird things... and the thirth list doesn't work...
     
    Tehy, Oct 16, 2007 IP
  4. Tehy

    Tehy Peon

    Messages:
    254
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Anyone? I'm new with this stuff :)
     
    Tehy, Oct 16, 2007 IP
  5. Lordy

    Lordy Peon

    Messages:
    1,643
    Likes Received:
    29
    Best Answers:
    0
    Trophy Points:
    0
    #5
    well, i actually just get
    when i select something from the second one.

    try adding this to your first

    value="<?=$_POST['myform1']?>"
    PHP:
    at least, i think thats how you set default in select forms? sorry, i'm not too sure how you would set the default. at any rate, just change "value" to whatever you need to set the default.

    this should set it only if it has an option selected, but if not, then you can just loop it into an if function
     
    Lordy, Oct 16, 2007 IP