I am trying to use the hook_form_alter to change the option that is selected by default within a select pull-down when the page loads. I am able to adjust the order of the options before the page loads but changing the #default_value option does not change the actual selected option when the page loads. Note function <i>product_type_form_alter </i>below:<br>
<br><i>function product_type_form_alter(&$form, &$form_state, $form_id) {<br> if ($form_id == 'views_exposed_form') {<br> $form['term_node_tid_depth']['#default_value'] = 184;<b>//this did not work</b><br>
$form['term_node_tid_depth']['#options'] = Array(193 => "Alpena County", 184 => "Genesee County", 190 => "Montmorency County", 186 => "Oceana County", 204 => "Wabasha County", "All" => "<Any>");<b>//this worked</b><br>
$form['term_node_tid_depth']['#default_value'] = 184;<b>//this did not work</b><br> dd($form['term_node_tid_depth']['#default_value']);<b>//the outputted log value is correctly as 184 but when the page loads it uses the original default of "All"</b><br>
}<br>}</i><br><br>If I instead include a javascript file within hook_form_alter (<b><i>listed below</i></b>) then I am able to change the actual selected option after the page loads and programmatically click the submit button to rerun the filter, but this is needless processing that causes the page to load twice. How can I use the method above to change the actual selected option before the page loads?<br>
<br>Thanks,<br><br>John<br><br><i>function product_type_form_alter(&$form, &$form_state, $form_id) {/<b>/this worked completely<br> </b>if ($form_id == 'views_exposed_form') {<br> $term_node_tid_depth_get = $_GET['term_node_tid_depth'];<br>
if (!isset($term_node_tid_depth_get)) {<br> drupal_add_js(drupal_get_path('module', 'product_type') . '/js/subscription_product_filter.js','module','footer');<br> }<br> }<br>
<br>'/js/subscription_product_filter.js' contents below:<br>jQuery("select#edit-term-node-tid-depth option[selected]").removeAttr("selected");<br>jQuery("select#edit-term-node-tid-depth option[value='184']").attr("selected", "selected"); <br>
$("#edit-submit-Subscription-Products").click();</i><div style="visibility: hidden; display: inline;" id="avg_ls_inline_popup"></div><style type="text/css">#avg_ls_inline_popup { position:absolute; z-index:9999; padding: 0px 0px; margin-left: 0px; margin-top: 0px; width: 240px; overflow: hidden; word-wrap: break-word; color: black; font-size: 10px; text-align: left; line-height: 13px;}</style>