SitePoint Sponsor |
|
User Tag List
Results 1 to 6 of 6
-
Jun 19, 2007, 00:31 #1
- Join Date
- May 2007
- Posts
- 28
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Best way to show selected option in List Box
I need a way so that we can show selected option in list box without using if condition in loop since some times we have lot of options and we have too much if conditions to check.
PHP Functions Class/Php Stuff: php-classes-functions.blogspot.com
SMS World: sms-treasure.blogspot.com
Finance Business India: financebusinessindia.blogspot.com
Retail Market India: retailmarketindia.blogspot.com
-
Jun 19, 2007, 01:19 #2
- Join Date
- Oct 2006
- Location
- Kathmandu, Nepal
- Posts
- 4,013
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
I am not sure whether it is possible to make an option selected in the list box without using if or any other types of conditional statements in PHP. But if you have taken the options from the database table or from any of the arrays, then you don't have to make any more than one if statement for selection.
If possible to do so without using conditions, it would be helpful to me too.
Thanks.Mistakes are proof that you are trying.....
------------------------------------------------------------------------
PSD to HTML - SlicingArt.com | Personal Blog | ZCE - PHP 5
-
Jun 19, 2007, 23:04 #3
- Join Date
- May 2007
- Posts
- 28
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
still waiting for a solution
PHP Functions Class/Php Stuff: php-classes-functions.blogspot.com
SMS World: sms-treasure.blogspot.com
Finance Business India: financebusinessindia.blogspot.com
Retail Market India: retailmarketindia.blogspot.com
-
Jun 19, 2007, 23:24 #4
- Join Date
- Oct 2006
- Location
- Kathmandu, Nepal
- Posts
- 4,013
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Could you post your array or data to be shown in the list box? So that we could discuss here further clearly. But i dont think that you can do it without using any type of conditions. From where you data comes for populating the list?
Mistakes are proof that you are trying.....
------------------------------------------------------------------------
PSD to HTML - SlicingArt.com | Personal Blog | ZCE - PHP 5
-
Jun 19, 2007, 23:41 #5
- Join Date
- Nov 2005
- Location
- The Netherlands
- Posts
- 808
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Why can't you do this:
PHP Code:$selected = isset($_POST['posted_value']) ? $_POST['posted_value'] : 'default';
foreach ($options as $option)
{
print '<option value="'.$option.'"';
if ($option == $selected) print ' selected="selected"';
print '>' . $option . '</option>';
}
-
Jun 21, 2007, 03:31 #6
- Join Date
- May 2007
- Posts
- 28
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Finally found a way:
I set the particular array index that is my selected value with value "selected" and repeated that array for all option values, when i reached that value it added "selected" in that option.
Code:<select name="isalutation_id" > <? $salutations = Get_Details($obj,'salutation_mast','','isalutation_id'); $selArrVal[$row[0]['isalutation_id']] = "selected"; for($i=0;$i<count($salutations);$i++){ ?><option value="<?=$salutations[$i]['isalutation_id']?>" <?=$selArrVal[$salutations[$i]['isalutation_id']]?> ><?=$salutations[$i]['vsalutation']?></option><? } ?> </select>
PHP Functions Class/Php Stuff: php-classes-functions.blogspot.com
SMS World: sms-treasure.blogspot.com
Finance Business India: financebusinessindia.blogspot.com
Retail Market India: retailmarketindia.blogspot.com
Bookmarks