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

  • SEARCH
  • Home
  • 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 7879219
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T03:51:17+00:00 2026-06-03T03:51:17+00:00

I am generating a checkbox using the corresponding method of CHtml , and I

  • 0

I am generating a checkbox using the corresponding method of CHtml, and I want to run some JavaScript code before and after the AJAX request. Here is the code:

echo CHtml::checkBox('markComplete', FALSE, 
    array(
        'class' => 'markComplete',
        'ajax'  => array(
            'type'       => 'POST',
            'url'        => $this->createUrl('/events/events/MarkComplete'),
            'data'       => 'event_status='.$events['id'],
            'beforeSend' => 'function(){ $(this).parent("TR").hide(); }',
            'success'    => 'function(resp) { $("#right").append(resp); }'
        ),
    )
); 

How can I tell Yii that beforeSend and success are JavaScript code and not plain strings?

  • 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-06-03T03:51:18+00:00Added an answer on June 3, 2026 at 3:51 am

    Better option available starting from Yii 1.1.11

    All framework classes now support custom JavaScript snippets through CJavaScriptExpression. Use it like this:

    'ajax' => array(
        'beforeSend' => new CJavaScriptExpression(
            'function(){ $(this).parent("TR").hide(); }'
        ),
        // ...
    )
    

    The option of prefixing strings with js: is still available by default, but it can now be disabled as required using an optional parameter on CJavaScript::encode.

    Original answer

    If you want to include literal JavaScript code as part of options, the convention in Yii is to prefix the code with js:. So you would write it like this:

    'ajax' => array(
        'type'=>'POST',
        'url'=>$this->createUrl('/events/events/MarkComplete'),
        'data'=>'event_status='.$events['id'],
        'beforeSend' => 'js:function(){            
            $(this).parent("TR").hide();
    
        }',
        'success'=>'js:function(resp) {
            $("#right").append(resp);
    
        }'
        ),
    )
    

    Unfortunately this is not well documented, which is why people run into exactly this problem every now and then.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to validate Checkbox in javascript, checkboxes is generating dynamically by PHP and
am generating pdf using Zend_pdf its saving after creating I want to open it
I am having some trouble generating a web form using fields specified in an
ClientID property of Dynamic CheckBox Problem: I need to attach some javascript function for
I am using <t:selectManyCheckbox> and <t:checkbox> for checkbox generating. <t:selectManyCheckbox id=selectone value=#{templatePrescriptionMaintenanceBackingBean.objectID} layout=spread styleClass=table
When generating models from postgresql with ColdFusion Illudium Code generator the boolean values get
I am generating a simple form with php. The following code has been reduced
I'm generating an unknown amount of checkboxes in my form using mysql, this number
To avoid reinventing the wheel, I am generating a form using CakePHP's form helper,
When generating IL using DynamicMethod it's possible to call methods and access fields that

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.