I have a problem to make a date and a list element in a form in HTML invisible if the user selects one way, and visible if the user selects two. How can I write the JavaScript code for that?
1 Answer
No need to write JavaScript for that; if you are working in PHP, you can use #states on the form element.
Example: form_example_states_form.
$form['high_school'] = array(
'#type' => 'fieldset',
'#title' => t('High School Information'),
// This #states rule says that the "high school" fieldset should only
// be shown if the "student_type" form element is set to "High School".
'#states' => array(
'visible' => array(
':input[name="student_type"]' => array('value' => 'high_school'),
),
),
);
-
but how if i'm using radio button to select.Does the same code can be used in php?? Commented May 7, 2013 at 2:40
-
Yes, as written in the doc link above, #states can be used with any form element Commented May 7, 2013 at 3:07
-
with the secret santa knowledge that
#states
is really emitting some simple jquery to show/hide stuff site since the action => condition array is just basically jquery selectors. A useful brief tutorial is at randyfay.com/states– tenkenCommented May 7, 2013 at 3:48 -
-