By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,747 Members | 1,671 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,747 IT Pros & Developers. It's quick & easy.

Less-expensive way to set up defaults in lists etc?

P: n/a
I'm currently setting up default selections in <select> lists by
passing an array of those defaults as keys ( 'valuefoo' => true ) as
an argument to the function that sets up the list. Then, as I build
each <option>, I call array_key_exists ( thisoptionvalue,
arrayofdefaults ) to check whether to include the
'selected="selected"' string.

So the code looks something like

Routine ( array( 'valuefoo' => true, 'valuebar' => true ) ) ;
.....

function Routine ( $defaultvals )
{
for ( $i= etc. )
echo '<option....' . ( array_key_exists( 'curroptval',
$defaultvals ) ? 'selected="selected"' : '' ) . etc ' ;
}

(I've elided a lot of syntax, but you get the idea)

That seems slow and tedious. Does anyone know a cheaper way?

Thanks,
Margaret
--
(To mail me, please change .not.invalid to .net, first.
Apologies for the inconvenience.)
Jul 17 '05 #1
Share this question for a faster answer!
Share on Google+

This discussion thread is closed

Replies have been disabled for this discussion.