0

I have a content type which I am loading in a block as a form. I am looking to know which radio button out of 2 buttons was clicked so that I can display additional fields. What is the best way to achieve this using JavaScript?

<div class="form-item">
 <label>I am: <span class="form-required" title="This field is required.">*</span></label>
 <div class="form-radios"><div class="form-item" id="edit-field-org-or-part-value-organizer-wrapper">
 <label class="option" for="edit-field-org-or-part-value-organizer"><input type="radio" id="edit-field-org-or-part-value-organizer" name="field_org_or_part[value]" value="organizer"   class="form-radio" /> Organizer</label>
</div>
<div class="form-item" id="edit-field-org-or-part-value-participant-wrapper">
 <label class="option" for="edit-field-org-or-part-value-participant"><input type="radio" id="edit-field-org-or-part-value-participant" name="field_org_or_part[value]" value="participant"   class="form-radio" /> Participant</label>
</div>
</div>
</div>
0

You can try .change() But you should haver the radio button under the same div.

I've used it in drupal 7

function foo() {
var field = $('#YOURFIELD').val();
  alert(field);
}

$('#YOURFIELD').change(foo);

Read this http://api.jquery.com/change/ to know more about .change()

| improve this answer | |
1

If you want to have an 'other' type of field you could use: http://drupal.org/project/select_or_other

I maintain custom code to achieve what you want (on very long fake multistep forms) and don't recommend this, it quickly becomes very unmanageable.

| improve this answer | |
  • Hi,I have used select_or_other in a different situation but that is not the issue for me. I want to show the remainder of my form depending on which radio button was clicked. Its hard to use js directly in drupal and difficult to know which button was clicked. Trying to test which one it is. Thanks. – pal4life Sep 30 '11 at 16:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.