stoneycurtis
asked on
PHP Set default value in SELECT box
Hello,
I have a list of world countries in a select drop down box, other variables are added depending on the selection but I only want the United States to be selectable.
Given that the United States 'country_id' = 223, and 'name' = "United States", how would I set the default in the following code snippet:
I have a list of world countries in a select drop down box, other variables are added depending on the selection but I only want the United States to be selectable.
Given that the United States 'country_id' = 223, and 'name' = "United States", how would I set the default in the following code snippet:
<select name="address[<?php echo $address_row; ?>][country_id]" onchange="country(this, '<?php echo $address_row; ?>', '<?php echo $address['zone_id']; ?>');">
<option value=""><?php echo $text_select; ?></option>
<?php foreach ($countries as $country) { ?>
<?php if ($country['country_id'] == $address['country_id']) { ?>
<option value="<?php echo $country['country_id']; ?>" selected="selected"><?php echo $country['name']; ?></option>
<?php } else { ?>
<option value="<?php echo $country['country_id']; ?>"><?php echo $country['name']; ?></option>
<?php } ?>
<?php } ?>
</select>
The 'addaddress()' function looks like this:function addAddress() {	
	html = '<div id="tab-address-' + address_row + '" class="vtabs-content" style="display: none;">';
	html += ' <input type="hidden" name="address[' + address_row + '][address_id]" value="" />';
	html += ' <table class="form">';
	html += ' <tr>';
html += '	 <td><span class="required">*</span> <?php echo $entry_firstname; ?></td>';
html += '	 <td><input type="text" name="address[' + address_row + '][firstname]" value="" /></td>';
html += ' </tr>';
html += ' <tr>';
html += ' <td><span class="required">*</span> <?php echo $entry_lastname; ?></td>';
html += ' <td><input type="text" name="address[' + address_row + '][lastname]" value="" /></td>';
html += ' </tr>';
html += ' <tr>';
html += ' <td><?php echo $entry_company; ?></td>';
html += ' <td><input type="text" name="address[' + address_row + '][company]" value="" /></td>';
html += ' </tr>';	
html += ' <tr class="company-id-display">';
html += ' <td><?php echo $entry_company_id; ?></td>';
html += ' <td><input type="text" name="address[' + address_row + '][company_id]" value="" /></td>';
html += ' </tr>';
html += ' <tr class="tax-id-display">';
html += ' <td><?php echo $entry_tax_id; ?></td>';
html += ' <td><input type="text" name="address[' + address_row + '][tax_id]" value="" /></td>';
html += ' </tr>';			
html += ' <tr>';
html += ' <td><span class="required">*</span> <?php echo $entry_address_1; ?></td>';
html += ' <td><input type="text" name="address[' + address_row + '][address_1]" value="" /></td>';
html += ' </tr>';
html += ' <tr>';
html += ' <td><?php echo $entry_address_2; ?></td>';
html += ' <td><input type="text" name="address[' + address_row + '][address_2]" value="" /></td>';
html += ' </tr>';
html += ' <tr>';
html += ' <td><span class="required">*</span> <?php echo $entry_city; ?></td>';
html += ' <td><input type="text" name="address[' + address_row + '][city]" value="" /></td>';
html += ' </tr>';
html += ' <tr>';
html += ' <td><span id="postcode-required' + address_row + '" class="required">*</span> <?php echo $entry_postcode; ?></td>';
html += ' <td><input type="text" name="address[' + address_row + '][postcode]" value="" /></td>';
html += ' </tr>';
	html += ' <tr>';
html += ' <td><span class="required">*</span> <?php echo $entry_country; ?></td>';
html += ' <td><select name="address[' + address_row + '][country_id]" onchange="country(this, \'' + address_row + '\', \'0\');">';
html += ' <option value="223"><?php echo $text_select; ?></option>';
<?php foreach ($countries as $country) { ?>
html += ' <option value="<?php echo $country['country_id']; ?>"><?php echo addslashes($country['name']); ?></option>';
<?php }?>
html += ' </select></td>';
html += ' </tr>';
html += ' <tr>';
html += ' <td><span class="required">*</span> <?php echo $entry_zone; ?></td>';
html += ' <td><select name="address[' + address_row + '][zone_id]"><option value="false"><?php echo $this->language->get('text_none'); ?></option></select></td>';
html += ' </tr>';
	html += ' <tr>';
html += ' <td><?php echo $entry_default; ?></td>';
html += ' <td><input type="radio" name="address[' + address_row + '][default]" value="1" /></td>';
Thanks in advance for any help.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
possibly. lets make sure that you are supplying the right data to your function. use var_dump() to see what's in those variables.
var_dump ($address_row);
var_dump ($address);
var_dump ($text_select);
var_dump ($countries);
var_dump ($address_row);
var_dump ($address);
var_dump ($text_select);
var_dump ($countries);
ASKER