Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I have this array for checkbox:

        'name' => __('Latest Product',''),
        'desc' => __('Select if you want to display latest product',''),
        'id' => $prefix . 'checkbox',
        'type' => 'checkbox',
        'std' => ''

I want to add an attribute for onclick="chk(electronics, this.checked);" on this.

How can I do it?

share|improve this question
In which context do you have this checkbox? –  fischi Jan 2 '13 at 11:23
Your question is incomplete, provide complete code. –  sven Jan 2 '14 at 5:40

1 Answer 1

Store the ID in a variable, and access that variable in a JavaScript:

document.getElementById("<?php echo $checkbox_id; ?>").onclick = function() {
    chk(electronics, this.checked);

You can also collect multiple IDs in an array and run through that array later in your script. But avoid the onclick attribute in markup, this is bloat and bad code style. :)

share|improve this answer
Thanks for giving answer... –  Ashok Saini Jan 3 '13 at 4:58
it's not working in my file..... can i inlcude this line <input type="checkbox" id="checkbox" onclick="chk(electronics, this.checked);"> in above array..... –  Ashok Saini Jan 3 '13 at 5:17
You could add a separate key named onclick and use it in the script that converts the array into markup. You didn’t mention that script, so I cannot say how this works. –  toscho Jan 3 '13 at 14:17

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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