user1190221
user1190221

Reputation: 9

Zend_form and jquery

I want this function to run when I submit a form..

$submit = new Zend_Form_Element_Button('submit');
$submit->setAttrib('onclick', '---what should go here?---');

Client-side script:

$(document).ready(function() {  
    $('a[name=modal]').click(function(e) {
        e.preventDefault();
        var id = $(this).attr('href');
        var maskHeight = $(document).height();
        var maskWidth = $(window).width();
        $('#mask').css({
            'width':maskWidth,
            'height':maskHeight
        });
        $('#mask').fadeIn(1000);    
        $('#mask').fadeTo("slow",0.8);  
        var winH = $(window).height();
        var winW = $(window).width();
        $(id).css('top',  winH/2-$(id).height()/2);
        $(id).css('left', winW/2-$(id).width()/2);
        $(id).fadeIn(2000); 
    });
    $('.window .close').click(function (e) {
        e.preventDefault();
        $('#mask').hide();
        $('.window').hide();
    });     
    $('#mask').click(function () {
        $(this).hide();
        $('.window').hide();
    });         
});

Upvotes: 0

Views: 433

Answers (1)

Hari K T
Hari K T

Reputation: 4254

You don't want to use onclick when you are using jQuery

For example, consider the HTML taken from http://api.jquery.com/submit/

<form id="target" action="destination.html">
  <input type="text" value="Hello there" />
  <input type="submit" value="Go" />
</form>
<div id="other">
  Trigger the handler
</div>

The event handler can be bound to the form:

$('#target').submit(function() {
  alert('Handler for .submit() called.');
  return false;
});

The form can be generated via Zend_Form itself , but this is just for demonstration.

Upvotes: 2

Related Questions