Posting in the Magento forums has been disabled pending the implementation of a new and improved forum solution which should better serve the community.

For new questions please post at magento.stackexchange.com, the community-run support site for the Magento community. We will be providing updates on the new forum solution soon. For questions or concerns please email community@magento.com.

Magento Forum

What is //<![CDATA[ doing? 
 
Krisk
Jr. Member
 
Total Posts:  6
Joined:  2009-07-30
 

I see this line in magento and I would like to understand what it is doing.

It is:

//<![CDATA[

What is it doing? Here is an example of it in use:

<script type="text/javascript">
    
//<![CDATA[
    
var productAddToCartForm = new VarienForm('product_addtocart_form');
            
productAddToCartForm.submit = function(){
                    
if (this.validator.validate()) {
                            this
.form.submit();
                    
}
            }
.bind(productAddToCartForm);
    
//]]>
    
</script>

Has it just been commented out? Is it even doing anything?
Thank you!

 
Magento Community Magento Community
Magento Community
Magento Community
 
Damian Culotta
Enthusiast
 
Total Posts:  878
Joined:  2008-12-10
Argentina
 

A good explanation:

http://en.wikipedia.org/wiki/CDATA

 
Magento Community Magento Community
Magento Community
Magento Community
 
Krisk
Jr. Member
 
Total Posts:  6
Joined:  2009-07-30
 

Damián, thank you. I read it and understand Cdata. However what I still don’t understand is what it is doing in the example I gave above.

 
Magento Community Magento Community
Magento Community
Magento Community
 
Krisk
Jr. Member
 
Total Posts:  6
Joined:  2009-07-30
 

I found the answer to this question for anyone else looking. The Cdata is being added to hide the javascript from the validators so that they don’t parse this code.  Sometimes it wont validate because of the javascript so you use this cdata to comment the javascript out.

 
Magento Community Magento Community
Magento Community
Magento Community
Magento Community
Magento Community
Back to top