Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 855719
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T08:07:23+00:00 2026-05-15T08:07:23+00:00

Using the example at the following URL: http://www.kavoir.com/2009/02/php-drop-down-list.html How can I have that drop

  • 0

Using the example at the following URL: http://www.kavoir.com/2009/02/php-drop-down-list.html

How can I have that drop down menu pre-select one of the options such as ‘Apple’?

EDIT: Addition info

function showForm()

{
global $sProduct, $name, $product, $header_file, $footer_file, $form_width, $form_background, $form_border_color, $form_border_width, $form_border_style, $cell_padding, $left_col_width, $font_size;   
include $header_file; 
echo <<<EOD

<form method="post" class="cForm">
<table style="width:{$form_width}; padding:20px 7px 0px 7px; font-size:{$font_size}; background-color:{$form_background};" class="contactForm">
<tr>
<td style="width:{$left_col_width}; text-align:left; vertical-align:center; padding:{$cell_padding}; font-weight:bold; {$name[3]}">{$name[0]}</td>
<td style="text-align:left; vertical-align:top; padding:{$cell_padding};"><input type="text" name="{$name[1]}" value="{$name[2]}" size="25"/></td>
</tr>
<tr>
<td style="width:{$left_col_width}; text-align:left; vertical-align:center; padding:{$cell_padding}; font-weight:bold;">{$product[0]}</td>
<!--<td style="text-align:left; vertical-align:top; padding:{$cell_padding};"><select name="{$product[1]}">-->
<td style="text-align:left; vertical-align:top; padding:{$cell_padding};">
<select name="{$product[1]}">
    <option value="1"></option>
    <option value="2">item 2</option>
    <option value="3">item 3</option>
    <option value="4">item 4</option>
    <option value="5">item 5</option>
    <option value="6">item 6</option>
</select>
</td>
</tr>
<td style="width:{$left_col_width}; text-align:left; vertical-align:center; padding:{$cell_padding}; font-weight:bold; {$code[3]}">{$code[0]}</td>
<td style="text-align:left; vertical-align:top; padding:{$cell_padding};"><input type="submit" name="submit" value="Submit" style="border:1px solid #999;background:#E4E4E4;" /></td>
</tr>
<tr>
<td colspan="2" style="font-size:10px; text-align:left; vertical-align:middle; padding:{$cell_padding};">
0:(var_product[0] = ({$product[0]})) <br/>
1:(var_product[1] = ({$product[1]})) <br/>
2:(var_product[2] = ({$product[2]}))<br/>
3:(var_product[3] = ({$product[3]}))<br/>
4:(var_sProduct = ({$sProduct}))<br/>
</td>
</tr>
</table>
</form>

EOD;
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T08:07:24+00:00Added an answer on May 15, 2026 at 8:07 am

    I would throw another parameter into the generateSelect function that defines what the default is. You can do this with either the id of the option or by the name. For the following, I’ll use name to make it clearer.

    function generateSelect($name = '', $options = array(), $default = '') {
        $html = '<select name="'.$name.'">';
        foreach ($options as $option => $value) {
            if ($option == $default) {
                $html .= '<option value='.$value.' selected="selected">'.$option.'</option>';
            } else {
                $html .= '<option value='.$value.'>'.$option.'</option>';
            }
        }
    
        $html .= '</select>';
        return $html;
    }
    
    /* And then call it like */
    $html = generateSelect('company', $companies, 'Apple');
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Given the URL (single line): http://test.example.com/dir/subdir/file.html How can I extract the following parts using
I have a URL that is like the following: http://www.example.com/client/project/subdirectory/value/ I would like like
I have the following url which will always have a color variable attached: http://www.example.com/?new=yes&color=red&shape=square
I've got a url type:- http://www.example.com/products.php?cat=1 which I am able to rewrite to:- http://www.example.com/myproduct1
I've got the following directory setup: http://www.mysite.com/public/ I'm using the following rewrite to remove
I'm using the following to define root while in development: define('LOCAL_URL', 'http://localhost/~xampp/Mysite'); define('REMOTE_URL', 'http://example.com');
Please forgive the verbosity of the following code example. Using Delphi 2009, I created
I have the following so far: ^((http[s]?|ftp):\/\/)(([^.:\/\s]*)[\.]([^:\/\s]+))(:([^\/]*))?(((\/\w+)*\/)([\w\-\.]+[^#?\s]+)(\?([^#]*))?(#(.*))?)?$ Been testing against these: https://www.google.com.ar:8080/dir/1/2/search.html?arg=0-a&arg1=1-b&arg3-c#hash https://google.com.ar:8080/dir/1/2/search.html?arg=0-a&arg1=1-b&arg3-c#hash https://google.com:8080/dir/1/2/search.html?arg=0-a&arg1=1-b&arg3-c#hash
I am trying to follow what is being explained here: http://www.djangobook.com/en/2.0/chapter03/ (the confusing example
Given the following example (using JUnit with Hamcrest matchers): Map<String, Class<? extends Serializable>> expected

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.