Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3226704
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T16:29:17+00:00 2026-05-17T16:29:17+00:00

I am creating a custom zend form element that will require some javascript. I

  • 0

I am creating a custom zend form element that will require some javascript. I can add the javascript I need like this:

/**
 * Renders the javascript to the view.
 */
protected function _generateJavaScript()
{
    $this->view->headScript()->captureStart(); ?>

        $(document).ready(function(){
            alert('hello');
        });

    <?php $this->view->headScript()->captureEnd();
}

However, if this custom form element is used multiple times, the identical javascript will appear multiple times. Is there a way to only render the javascript once?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-17T16:29:18+00:00Added an answer on May 17, 2026 at 4:29 pm

    You might be able to do something like

    protected function _generateJavaScript()
    {
        if (!isset($this->view->scriptGenerated))
        {
            // generate the script, then...
            $this->view->scriptGenerated = true;
        }
    }
    

    since PHP objects can have “extra” properties.

    You’ll obviously want to pick a better name, that won’t clash if you have multiple scripts using the same pattern.

    Alternatively, you could have the script in a file. Looks like appendFile won’t include a script file more than once. I don’t immediately see any such protection for ad-hoc scripts.

    protected function _generateJavaScript()
    {
        $this->view->headScript()->appendFile('path/to/script.js');
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In WPF, we are creating custom controls that inherit from button with completely drawn-from-scratch
I'm creating some custom work items in TFS and the helptext field seems handy
I'm creating a custom drag helper (in jQuery): $('.dragme', element).draggable({ appendTo: 'body', helper :
I'm creating a custom Java Struts tag that is for building and formatting an
I am creating a custom WPF control that let's say for simplicity sake has
I'm looking into creating custom controls for WPF and I've found some reasonably useful
I am creating custom images that I later convert to an image pyramid for
I'm creating custom UITableViewCells using the approach outlined on this page: http://icodeblog.com/2009/05/24/custom-uitableviewcell-using-interface-builder/ So my
I needed some help with creating custom trees given an arithmetic expression. Say, for
i'm reading the android developer docs on creating custom components and one thing that's

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.