Alter DIV on Checkboxes

sarah

i want to have a series of yes/no questions, & depending on the RADIO BUTTON, the answer / text appears on the appropriate DIV.

I have found one answer - here and this does what i am after.

My question is, how easy is it to alter this so I can have MULTIPLE sets of radio buttons.

Ie

      <input type="radio" name="type" value="tuser1" id="tuser1" /> (question 1)
      <input type="radio" name="type" value="tuser2" id="tuser2" /> (question 2)
      <input type="radio" name="type" value="tuser3" id="tuser3" /> (question 3) etc.

is it easy to alter the function, to accept numeric references & to alter the approriate DIV set ?

PS - i assume i can have text of multiple lines/paragraphs in each DIV.

PPS: my ultimate aim is to combine the "visable" divs, into a master div underneath (with a blank line in each div reply).

IE,

Q1 (yes/no), (show answer to q1 "yes")/(show answer to q1 "no")

master div:-

show Q1 result.

show Q2 result.

show Q3 result.

etc...

i'll put the master div inside a TEXTAREA form - to send to another website for processing - on my server.

i want the master div to preserve any new-lines / formattng of the answers (if the answer is on several lines).

CJ Ramki

Wrap your each question set in div. By this you can easily group your question. You can use class and data attributes.

Try this code,

HTML :

<div id="Qset1">
    <input type="radio" id="deliverer" data-id="yes" value="deliverer" name="type" checked />
    <input type="radio" name="type" data-id="No" value="tuser" id="tuser" />
    <div id='optuser' class="yes">//some input fields1</div>
    <div id='optdeliverer' class="no">//some other input fields1</div>
</div>
<div id="Qset2">
    <input type="radio" id="deliverer" data-id="yes" value="deliverer" name="type2" checked />
    <input type="radio" name="type2" data-id="No" value="tuser" id="tuser" />
    <div id='optuser' class="yes">//some input fields2</div>
    <div id='optdeliverer' class="no">//some other input fields2</div>
</div>
<div id="Qset3">
    <input type="radio" id="deliverer" data-id="yes" value="deliverer" name="type3" checked />
    <input type="radio" name="type3" data-id="No" value="tuser" id="tuser" />
    <div id='optuser' class="yes">//some input fields3</div>
    <div id='optdeliverer' class="no">//some other input fields3</div>
</div>

JS :

$(document).ready(function () {
    $('input[type=radio]').change(function () {
        if ($(this).attr('data-id', 'yes').is(':checked')) $(this).closest('div').find('.yes').toggle();
        if ($(this).attr('data-id', 'no').is(':checked')) $(this).closest('div').find('.no').toggle();
    });
});

SEE THIS FIDDLE DEMO

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Div Checkboxes group by attribute

From Dev

Jquery checkboxes inside div

From Dev

Using javascript to alter content of a <div>

From Dev

Why does grouping ActiveX checkboxes alter OLEObject visibility

From Dev

Jquery refresh div alter show div time

From Dev

Dynamically alter contents of a div and append to another div

From Dev

How to check and uncheck all checkboxes inside a div

From Dev

Using JQuery to get the value of the unchecked checkboxes in a div

From Dev

Using form elements - checkboxes - inside contenteditable div

From Dev

How to check checkboxes differently depending on parent div?

From Dev

get id of all checked checkboxes in a div

From Dev

Using form elements - checkboxes - inside contenteditable div

From Dev

Selecting only checkboxes within the parent div

From Dev

show one div and hide another div onclick of list of checkboxes

From Dev

If one checkbox within a div that contains multiple checkboxes is checked, add class to all checkboxes

From Dev

Can't get Checkboxes to stop displaying a hidden Div

From Dev

Show/Hide div with checkboxes using classes multiple times on a page

From Dev

jQuery / JavaScript: Check all checkboxes and Check each checkbox to display div

From Dev

show a div when atleast two checkboxes has checked

From Dev

opening a div when a checkbox is checked and no of checkboxes are coming from database

From Dev

Add value, text and state to array for all checkboxes within a div

From Dev

Move selected checkboxes from one div to another. If unselect from the other div, it should reflect in the initial div

From Dev

jQuery: alter DIV that shares class with another DIV (but still owns a unique class also) only if some conditions were met

From Dev

jQuery: accordion-LIKE format. how to prevent div from collapsing if one of the checkboxes is checked

From Dev

Get Values from Checkboxes, Combine Each Div's Corresponding Data, and Change data-view

From Dev

Collection of checkboxes

From Dev

Checkboxes with formspree

From Dev

QComboBox with checkboxes

From Dev

Populating checkboxes

Related Related

  1. 1

    Div Checkboxes group by attribute

  2. 2

    Jquery checkboxes inside div

  3. 3

    Using javascript to alter content of a <div>

  4. 4

    Why does grouping ActiveX checkboxes alter OLEObject visibility

  5. 5

    Jquery refresh div alter show div time

  6. 6

    Dynamically alter contents of a div and append to another div

  7. 7

    How to check and uncheck all checkboxes inside a div

  8. 8

    Using JQuery to get the value of the unchecked checkboxes in a div

  9. 9

    Using form elements - checkboxes - inside contenteditable div

  10. 10

    How to check checkboxes differently depending on parent div?

  11. 11

    get id of all checked checkboxes in a div

  12. 12

    Using form elements - checkboxes - inside contenteditable div

  13. 13

    Selecting only checkboxes within the parent div

  14. 14

    show one div and hide another div onclick of list of checkboxes

  15. 15

    If one checkbox within a div that contains multiple checkboxes is checked, add class to all checkboxes

  16. 16

    Can't get Checkboxes to stop displaying a hidden Div

  17. 17

    Show/Hide div with checkboxes using classes multiple times on a page

  18. 18

    jQuery / JavaScript: Check all checkboxes and Check each checkbox to display div

  19. 19

    show a div when atleast two checkboxes has checked

  20. 20

    opening a div when a checkbox is checked and no of checkboxes are coming from database

  21. 21

    Add value, text and state to array for all checkboxes within a div

  22. 22

    Move selected checkboxes from one div to another. If unselect from the other div, it should reflect in the initial div

  23. 23

    jQuery: alter DIV that shares class with another DIV (but still owns a unique class also) only if some conditions were met

  24. 24

    jQuery: accordion-LIKE format. how to prevent div from collapsing if one of the checkboxes is checked

  25. 25

    Get Values from Checkboxes, Combine Each Div's Corresponding Data, and Change data-view

  26. 26

    Collection of checkboxes

  27. 27

    Checkboxes with formspree

  28. 28

    QComboBox with checkboxes

  29. 29

    Populating checkboxes

HotTag

Archive