Forums

Options, recipients and other fields

relecule 16 Oct, 2009
Hi

Hope somebody can help me.. I am designing a form that needs a option drop down that will email desired recipients depending on criteria selected. for Example:

Options:
General --> [email]general@domain.com[/email]
Sales --> [email]sales@domain.com[/email]
Support --> [email]support@domain.com[/email]
Other --> [email]General@domain.com[/email]

Now I managed to get the above to work by creating dynamic email to fields. The only problem I have is that we need the form to have a extra text field to appear when a user selects "other". So if Other is selected then this text box or text area will display and if one of the other options is selected then this text box will not display or be grayed out.

any help will be greatly appreciated..
GreyHead 16 Oct, 2009
Hi relecul,

Here's an example of a chunk of code to do this with a slightly different drop-down.
<?php
$script = "
var source = $('source');
var source_other = $('source_other');
source_other.disabled = true;
source.addEvent('change', function() {
  if ( source.value == 'Other' ) {
    source_other.disabled = false;
  } else {
    source_other.disabled = true;
  }
});
";
$script = "
window.addEvent('domready', function() {
$script;
});
";
$doc =& JFactory::getDocument();
$doc->addScriptDeclaration($script);
        $options['source'] = array(
            '' => '~?~',
            'Google' => 'Google',
            'Yell.com' => 'Yell.com',
            'Friday ad - press' => 'Friday ad in local press',
            'Friday ad - on-line' => 'Friday ad on-line',
            'Word of mouth' => 'Word of mouth',
            'Other' => 'Other (please describe)'
        );
        $options_array = array();
        foreach  ( $options['source'] as $k => $v ) {
            $selected = "";
/*
            if ( $k == $client->source ) {
                $selected = "selected='selected'";
            }
*/
            $options_array[] = "<option value='$k' $selected >$v</option>";
        }
?>
<div class="form_item">
  <div class="form_element cf_dropdown">
    <label for='source' class="cf_label" style="width: 150px;">How did you hear about us?</label>
    <select class="cf_inputbox" id="source" size="1" title=""  name="source">
	<?php
	    echo implode(' ', $options_array);
	?>
    </select>
  </div>
  <div class="cfclear"> </div>
</div>

<div class="form_item">
  <div class="form_element cf_textbox">
    <label class="cf_label" for='source_other' style="width: 150px;">If you said 'other', please add details</label>
    <input class="cf_inputbox" maxlength="150" size="30" title="" id="source_other" name="source_other" type="text" />
  </div>
  <div class="cfclear"> </div>
</div>

<div class="form_item">
  <div class="form_element cf_button">
    <input type='submit' name='submit' id='submit' value='Submit' />
  </div>
  <div class="cfclear"> </div>
</div>
The action here is to enable or disable the text box - you could change this to do something different.
This topic is locked and no more replies can be posted.