tags:

views:

180

answers:

1

Ultimately, I'd like my Zend Form to render this HTML:

<p>Do you have any documents to upload?</p>
<p>Yes <input type="radio" value="Yes" name="uploadChoice" onClick="showTable()">&nbsp;&nbsp;No <input type="radio" value="No" name="uploadChoice" onClick="hideTable()" checked></p>

Here's what I have in my Zend_Form:

//create radio buttons
$uploadQuestion = new Zend_Form_Element_Radio('upLoadQuestion');
$uploadQuestion->setLabel('Do you have any documents to upload?')
->addMultiOptions(array(
'yes' => 'Yes',
'no' => 'No'
))
->setSeparator(' ');

The problem I'm running into is how to add the onClick="showTable()" and onClick="hideTable()" elements to their respective radio buttons.

In the alternative, I could rework the javascript and add something like onClick="toggleTable()" to the radio buttons if I can't add something different to each of the radio buttons. But, will Zend let me do that?

+1  A: 

You just need to use setAttrib like this:

$uploadQuestion->setAttrib('onClick','showTable();'); Obviously, in this case, you'll have to use the same JS function for all the radio buttons of the "uploadQuestion" radiogroup.

Hope it will help somenone.

Marco