Forums

Required field depending on another

tonythetiger 12 Nov, 2010
Hi!
In a form that I am building, I ask first if you are attending to the celebration with two radio buttons. If you answer YES I need people to also introduce "number of people" in a text field (so it has to be required). But I need to make NOT required the text field "number of people" if they check the radio button NO.
How can I do it?

Thanks in advance.
GreyHead 17 Nov, 2010
Hi tonythetiger ,

This can be done fairly easily but needs a little custom JavaScript to enable the "number of people" input and validate it.

Bob
SPABO 30 Nov, 2010
Strugggling with the same problem, would it be possible to "show"
a "<div class="form_element cf_textbox">" only once YES is selected (selectbox)

I do hav a simalar JS to show new "selectboxes", but thos have an unique fieldset.

So, how to handle cf_textboxes in the same way???
SPABO 30 Nov, 2010
Hi Bob
Pls fins a JS, it seems to be working, however, when Nee is selected in select_2, everything after the three cf_textboxes (Voornaam, Achternaam, EGAHCP) disappear, including teh submit and reset buttons
Where do I get wrong....🙄

<?
$doc =& JFactory::getDocument();
$script = "window.addEvent('domready', function() {
  $('select_2').addEvent('change', function(event) {
    var e = new Event(event);
    if (e.target.value == 'Ja') {
      $('Voornaam').getParent().getParent().setStyle('display', 'block');
    } else {
      $('Voornaam').getParent().getParent().setStyle('display', 'none');
    }
  });
});";
$doc->addScriptDeclaration($script);
?>

<?
$doc =& JFactory::getDocument();
$script = "window.addEvent('domready', function() {
  $('select_2').addEvent('change', function(event) {
    var e = new Event(event);
    if (e.target.value == 'Ja') {
      $('Achternaam').getParent().getParent().setStyle('display', 'block');
    } else {
      $('Achternaam').getParent().getParent().setStyle('display', 'none');
    }
  });
});";
$doc->addScriptDeclaration($script);
?>

<?
$doc =& JFactory::getDocument();
$script = "window.addEvent('domready', function() {
  $('select_2').addEvent('change', function(event) {
    var e = new Event(event);
    if (e.target.value == 'Ja') {
      $('EGAHCP').getParent().getParent().setStyle('display', 'block');
    } else {
      $('EGAHCP').getParent().getParent().setStyle('display', 'none');
    }
  });
});";
$doc->addScriptDeclaration($script);
?>
This topic is locked and no more replies can be posted.