Associative array thing

Hello,

For example I have array that looks like this:

[php]$something = array(“20/3/2012” => “25”);[/php]

I have one form with two select or dropdown menus. and my code looks like this.

[php]echo “”;
echo "Mesec: ";
echo “”;

foreach($Meseci as $m => $f)
{
echo “”.$m."";
}
echo “”;

echo " Dan: ";
echo “”;

foreach($Meseci as $m => $f)
{

echo “”.$f."";
}

echo “”;
echo “”;[/php]

What I want to do is that when one select option is clicked, I get other one filled with that “=>25” number. Now, what I have been trying to do is that on change, first dropdown menu auto submits and that works, but then select option is not getting replaced to what I have selected. I didn’t add to this code here, but I have been trying with $_POST variable and it either ends up with first form gets filled with just one name, or it doesnt remember which one was last selected.

Is there a way to handle this? Also, can I make form to autosubmit to its self? because I woud probably need two similar forms and I need selections to be different (to remember different).

Thanks.

Ummm, you post PHP but you want a javascript I assume…
( so now I’m confused whether you want to achieve this client- or serverside, I’m assuming clientside )

The javascript will have to have a copy of the entire hash, I’m sorry, associative array, but then in javascript of course.
Then you need a javascript function that gets called ‘onChange’ in the first select that selects the correct entry in the second.

var assarr = { "20/3/2012" : "25" };

function updateSelect()
{   var selelm1 = document.DatumPreuz.mesec;
    var selelm2 = document.DatumPreuz.dan;

    var select = asarr[selelm1.value];

    for ( i=0; i<selelm2.options.length; i++ )
    {   if ( selelm2.options[i].selected )
        {   selelm2.options[i].selected = false;
        }
        if ( selelm2.options[i].value == select )
        {   selelm2.options[i].selected = true;
        }
    }
}

(something along those lines, code not validated)

For your second question, what do you mean by ‘autosubmit’. Don’t you want to leave it to the users to decide whether to submit or not? ( If I discover a script submitting stuff to a server without my action I stop the script ) anyway, I have no clue what you’re trying to do there…

but I hope I helped a bit.

Good luck!
O.

Sponsor our Newsletter | Privacy Policy | Terms of Service