Acheron Posted May 27, 2004 Posted May 27, 2004 I've seen a number of different ways to set this up regarding the country selection for instance in 'Create Account.' However, none of the solutions I've come across so far are really done properly. i.e. One option makes it so that it is only fixed in the 1 file. The better option still has the flaw of creating duplicate options within the pulldown. So would anyone happen to know how to set it to select an option w/o displaying a duplicate of that option? tia :)
Paycheck Posted May 28, 2004 Posted May 28, 2004 I am not quite clear on what options you are talking about. Are you talking about a product option or "Attribute" for a product, you mention "country" under create accounts. What exactly are you trying to accomplish and or do? JM Always remember, we need patience, guidance and most of all understanding. My Contributions
Acheron Posted May 28, 2004 Author Posted May 28, 2004 Well, atm I am trying to set 2 default selected options ... (1) United States for 'Country' option in the Create Account (2) Taxable Goods in admin under Add New Product I am able to set a default option like this for example: Change ... $tax_class_array = array(array('id' => '', 'text' => TEXT_NONE)); to $tax_class_array = array(array('id' => '1', 'text' => 'Taxable Goods')); But that's not really the proper way to do it b/c it creates 2 Taxable Goods options in the pulldown. I would like it to select the Taxable Goods existing option w/o creating a new option. To clarify, I want it to do the equivalent of this HTML: <select size="1" name="taxclass"> <option value="1" selected>Taxable Goods</option> <option value="2">Non-Taxable Goods</option> </select>
peterr Posted May 28, 2004 Posted May 28, 2004 Hi, Not too sure if I understand the problem, anyway ........... There is a common osC function called tep_draw_pull_down_menu() From PHPXref ....... Function and Method Cross Referencetep_draw_pull_down_menu() Defined at: * /includes/functions/html_output.php -> line 262 * /admin/includes/functions/html_output.php -> line 275 Here is the code from /html_output.php 261 // Output a form pull down menu 262 function tep_draw_pull_down_menu($name, $values, $default = '', $parameters = '', $required = false) { 263 $field = '<select name="' . tep_output_string($name) . '"'; 264 265 if (tep_not_null($parameters)) $field .= ' ' . $parameters; 266 267 $field .= '>'; 268 269 if (empty($default) && isset($GLOBALS[$name])) $default = stripslashes($GLOBALS[$name]); 270 271 for ($i=0, $n=sizeof($values); $i<$n; $i++) { 272 $field .= '<option value="' . tep_output_string($values[$i]['id']) . '"'; 273 if ($default == $values[$i]['id']) { 274 $field .= ' SELECTED'; 275 } 276 277 $field .= '>' . tep_output_string($values[$i]['text'], array('"' => '"', '\'' => ''', '<' => '<', '>' => '>')) . '</option>'; 278 } 279 $field .= '</select>'; 280 281 if ($required == true) $field .= TEXT_FIELD_REQUIRED; 282 283 return $field; 284 } Notice the third parameter, the variable , $default, if you DO pass that, then the code will add the tag option "selected". Peter
Acheron Posted May 28, 2004 Author Posted May 28, 2004 Well peterr, for not being too sure you understood, I think you understood perfectly. ;) I ended up changing this: tep_draw_pull_down_menu('products_tax_class_id', $tax_class_array, $pInfo->products_tax_class_id, 'onchange="updateGross()"'); ?> to tep_draw_pull_down_menu('products_tax_class_id', $tax_class_array, $default = '1', $pInfo->products_tax_class_id, $required = false, 'onchange="updateGross()"'); ?> The only issue to sort now, and it's not all that important in this instance ... but I'd still like to learn ... What and where would I add the code so that if the field isn't empty, it selects the current value instead of the default option? i.e. in the event you edit the product, etc.
Acheron Posted May 28, 2004 Author Posted May 28, 2004 I have this further up and perhaps that's where I should have been looking in the first place ..?? for ($i=0, $n=sizeof($tax_class_array); $i<$n; $i++) { if ($tax_class_array[$i]['id'] > 0) { echo 'tax_rates["' . $tax_class_array[$i]['id'] . '"] = ' . tep_get_tax_rate_value($tax_class_array[$i]['id']) . ';' . "\n"; } ... but keep in mind my PHP knowledge is extremely limited. Learning as I go. :)
Acheron Posted May 28, 2004 Author Posted May 28, 2004 Just needed a night's sleep, was extremely easy and obvious. Thanks for the info on the $default variable Peter. :)
blah45 Posted August 16, 2004 Posted August 16, 2004 Acheron: what did you change to fix the problem of it always showing the selected option even if you've edited the product to have a different value? Thanks
Guest Posted August 17, 2004 Posted August 17, 2004 Acheron: what did you change to fix the problem of it always showing the selected option even if you've edited the product to have a different value? Thanks The below example isn't quite accurate but I'm just trying to give an example. I would do something like this: if $pInfo['products_tax_class_id'] == '' { $default = '1'; } else { $default = $pInfo['products_tax_class_id'] } tep_draw_pull_down_menu('products_tax_class_id', $tax_class_array, $default, $pInfo->products_tax_class_id, $required = false, 'onchange="updateGross()"'); If there was no value in that field, it would set it to your choice of default. If there was a value, it would select that value as the option.
Recommended Posts
Archived
This topic is now archived and is closed to further replies.