Quantcast

Form from INI multiOptions

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Form from INI multiOptions

Bob O
I have a set of radio buttons in a from generated from an ini file..

im trying to add to different onclick method calls based on which one is selected

this is a short snippet of what i have

; Broadcast Message Recipients Radios
advertiser.broadcast.elements.broadcastRecipientsRadio.type = "radio"
advertiser.broadcast.elements.broadcastRecipientsRadio.options.true = "false"
advertiser.broadcast.elements.broadcastRecipientsRadio.options.multiOptions.all = "All"
advertiser.broadcast.elements.broadcastRecipientsRadio.options.multiOptions.all.attribs.onclick = "selectAll()"
advertiser.broadcast.elements.broadcastRecipientsRadio.options.multiOptions.selected = "Selected"
advertiser.broadcast.elements.broadcastRecipientsRadio.options.multiOptions.selected.attribs.onclick = "unselectAll()"
advertiser.broadcast.elements.broadcastRecipientsRadio.options.attribs.alt = "Broadcast"
advertiser.broadcast.elements.broadcastRecipientsRadio.options.value = "all"
advertiser.broadcast.elements.broadcastRecipientsRadio.options.decorators.type = "ViewHelper"


but im unable to set the attribs.onclick for each radio button.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: Form from INI multiOptions

vinnyman
From my understanding, you'll have to use an onchange event at the higher level and inspect which option is selected in the corresponding javascript function (not provided here, sorry for being lazy).

Something of the likes of :

      advertiser.broadcast.elements.broadcastRecipientsRadio.onchange = "goZendgo()"

I personally find it lame that you cannot assign a function to an onclick event directly in the option tag ... That whole Zend_Form structure is a mess.  Matthew O'Phinney et al. should have thought it through.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: Form from INI multiOptions

Fred Jiles
They probably chose not to allow you to use the onclick tag for this because it is not good standards to use inline javascript.  I am also sure they would advise against using style="" as well.

Another question is why do you even need to use javascript?  If you have two buttons one has a value of submit, and the other cancel.  When you process the form can't you just check to see which one was clicked just like you would with any php form and not need the javascript at all?

$cancel = new Zend_Form_Element_Submit("Cancel");

if ($this->getRequest()->isPost() && $this->getRequest()->getParam('Cancel')=='Cancel'){
       redirect to whatever when cancel is clicked
}

On Tue, Oct 6, 2009 at 3:43 PM, vinnyman <[hidden email]> wrote:

From my understanding, you'll have to use an onchange event at the higher
level and inspect which option is selected in the corresponding javascript
function (not provided here, sorry for being lazy).

Something of the likes of :

     advertiser.broadcast.elements.broadcastRecipientsRadio.onchange =
"goZendgo()"

I personally find it lame that you cannot assign a function to an onclick
event directly in the option tag ... That whole Zend_Form structure is a
mess.  Matthew O'Phinney et al. should have thought it through.
--
View this message in context: http://www.nabble.com/Form-from-INI-multiOptions-tp22568875p25775365.html
Sent from the Zend Framework mailing list archive at Nabble.com.


Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: Form from INI multiOptions

vinnyman
My guess here is that the need of a JavaScript function was to catch an event without having to refresh the page.  Your example is correct as long as you don't mind the refresh.  Hence I find it's more or less relevant here.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: Form from INI multiOptions

Hector Virgen
I agree with Fred. It's much easier to write your javascript in a separate .js file instead of adding inline javascript. Inline javascript tends to become difficult to maintain over time.

In jQuery you could write something like this:

$(':checkbox[name="broadcastRecipientRadio"][value="all"]').click(function(event)
{
    $(':checkbox[name="broadcastRecipientRadio"]').attr('checked', 'checked');
});

An even better way to write it would be to observe all checkboxes that have the value "all" and automatically check related checkboxes when clicked. You would only have to write it once and just include it on every page:

$(':checkbox[value="all"]').click(function(event)
{
    var checkbox = $(this);
    var name = checkbox.attr('name');
    $(':checkbox[name="' + name + '"]').attr('checked', 'checked');
});

Once you break out of using inline javascript, it all of a sudden becomes much friendlier :)

--
Hector


On Tue, Oct 6, 2009 at 1:20 PM, vinnyman <[hidden email]> wrote:

My guess here is that the need of a JavaScript function was to catch an event
without having to refresh the page.  Your example is correct as long as you
don't mind the refresh.  Hence I find it's more or less relevant here.
--
View this message in context: http://www.nabble.com/Form-from-INI-multiOptions-tp22568875p25775900.html
Sent from the Zend Framework mailing list archive at Nabble.com.


--
Hector Virgen
Loading...