Hi

Question:

  1. How do I grab the selected value from Javascript post onchange?
  2. What approach must I do to implement change to my page post onchange and I have the selected value?

I have defined a content that has two pull-down menus, form attribute '#type' => 'select', to two forms A and B on the same page.

How B's form #options is populated is dependent upon what option is selected within A's form #options. Thereby, initially set B's form #disabled => TRUE until A's form onchange has a new value.

I have provided A's form onchange attribute with a javascript function:

    $form['A'] = array(
      '#type'           => 'select',
      '#title'          => t('A'),
      /* more stuff here... */
      '#attributes' => array('onchange' => 'A_onlick(this.selectedIndex)'),
   );

javascript code:

function A_onlick(value_A_id) {
	alert("A:" + value_A_id);
	// Not sure what goes here...
	};

Drupal php code:

  $A_id_selected = // Not sure what goes here...

And post onclick, do I need to implement hook_form_alter() so that the second B's pull-down receives the Javascript value and thereby B's form #options can be populated?

Thanks

Jeff in Seattle

Comments

c4marcus’s picture

I too am looking for an answer to this one!

ajaykarthi’s picture

in your javacript need to do a document.getElementById("element id").value