On May 22, 3:30 pm, Randy Johnson - CFConcepts
<[EMAIL PROTECTED]> wrote:
> I have a page that auto loads States and Cities from a database.
>
> When you change the state, the city name changes.
>
> This works fine on the page when you go to fill it out for the first time.
>
> What I can seem to find anywhere is how to pre select the boxes if I am
> doing an edit on the page.
>
> For example:
>
> If I fill out the form with South Carolina as the state and Myrtle Beach
> as the city, how do I go about getting the state select box to have
> South Carolina Selected, then have the city list load with the South
> Carolina Cities but have Myrtle Beach Selected.
>
> I will keep reading over the mailing list archives and plugins to find
> an answer, in the meantime if anyone could help me out I'd appreciate it.

Without knowing your edit sequence, this is going to be generic and
possibly not quite applicable.  In final code, I would also prefer
that things were handled by events (so that #city figured itself out
after you changed #state), but that requires more knowledge than I
have of your app in order to implement intelligently.

::html::
<select id="state" name="state"></select>
<select id="city" name="city"></select>

::script::
function loadStateCity(stateid, cityid) {
        $s.val(stateid);
        loadCity(stateid, cityid);
}

function loadCity(stateid, cityid) {
        $c.load('getcityoptions.php?stateid=' + stateid, function() {
                if (typeof cityid != 'undefined')
                        $('option[value=' + cityid + ']', $c).attr('selected', 
'true');
        });
}

~Pyro

Reply via email to