PHP array problem?

Posted by needHeLp on Stack Overflow See other posts from Stack Overflow or by needHeLp
Published on 2010-03-07T22:53:34Z Indexed on 2010/03/07 23:11 UTC
Read the original article Hit count: 259

Filed under:
|

I'm new to PHP and I want this code <option value="" disabled="disabled">-------------</option> to be disabled when the php code is building my select list of options. How can I fix my php code so it will always set that specific option to disabled?

Here is part of the php code.

echo '<select name="country" id="country" size="20">' . "\n";
  foreach($countries as $option) {
    if ($option == $state) {
      echo '<option value="' . $option . '" selected="selected">' . $option . '</option>' . "\n";
    } else {
      echo '<option value="'. $option . '">' . $option . '</option>'."\n";
    }
  }
echo '</select>';

Here is part of the HTML code that is outputed from the php code.

    <option value="United States">United States</option>
    <option value="Australia">Australia</option>
    <option value="Canada">Canada</option>
    <option value="United Kingdom">United Kingdom</option>
    <option value="India">India</option>
    <option value="" disabled="disabled">-------------</option>
    <option value="Afghanistan">Afghanistan</option>
    <option value="Aland Islands">Aland Islands</option>

    <option value="Albania">Albania</option>
    <option value="Algeria">Algeria</option>
    <option value="American Samoa">American Samoa</option>
    <option value="Andorra">Andorra</option>

© Stack Overflow or respective owner

Related posts about php

Related posts about html