Jordi Castilla
Jordi Castilla

Reputation: 26981

Add event to checkbox[] in wordpress plugin contact form 7

I want to add a change, click or any other event to detect when checkbox change to show a hidden field. I achieved to reproduce this demo and it's working using a dropbox, now I want to customize with a checkbox.

If I use an accept checkbox it works like a charm in this way:

[acceptance name id:name]

Creates

<input type="checkbox" id="name" value="Value">

Then

$('#name').change(function() {
    if ($("#name")[0].checked == true) {

But as long as checkbox creates an array even with one option:

[checkbox name id:name "Value"]

Creates

<input type="checkbox" name="name[]" value="Value">

When I do same does not work. I can find checked value using this ugly path:

$("#name")[0].childNodes[0].childNodes[0].checked

But change, click or other events are not present to set up...

How can I access to event in the checkbox to show hidden field when checked?

Upvotes: 1

Views: 1343

Answers (1)

Rayon
Rayon

Reputation: 36609

If you are selecting elements considering array like name attributes or just name attributes, Use attribute selector(jQuery( "[attribute='value']" )).

For example, $('[name="name[]"]').on('EVENT',HANDLER)

Upvotes: 2

Related Questions