2

I get Uncaught SyntaxError: Unexpected identifier message on click view button!?

I think problem is in this part: onClick="showModal('+value+');"

because of when i call the function out of [onClick=""], [showModal(value);] it's work!

what's wrong? any idea?

thanks.

JQUERY :

jQuery(document).ready(function($){

    divElement='';
    $.ajax({        
       type: "POST",
       url: "<?php echo Yii::app()->createUrl('itemtype/index');?>",
       data:{},
       dataType: "json",
       success: function(data) {

           $.each( data, function( i, value ) {
                    //showModal(value);
                    divElement+='<li class="itemtype-buttons">'+
                                '<a class="itemtype-button" href="#" onClick="showModal('+value+');" data-toggle="tooltip" data-original-title="View"><i class="fa fa-eye"></i></a>'+
                                '<a class="itemtype-button" href="#" data-toggle="tooltip" data-original-title="Edit"><i class="fa fa-edit"></i></a>'+
                                '<a class="itemtype-button" href="#" data-toggle="tooltip" data-original-title="Delete"><i class="fa fa-times"></i></a>'+
                                '<a class="itemtype-button" href="#" data-toggle="tooltip" data-original-title="List of '+value['name']+'"><i class="fa fa-bars"></i></a>'+
                                '</li>';
                });

            divElement+='</div>';                           
            $('#itemtypes').html(divElement);   

       }
    });

}); 

//itemtype Controller
public function actionIndex()
{
        $data = Itemtype::model()->findAll();
        echo CJSON::encode($data);

}
 function showModal(arr){

            alert(arr['name']);
}

Thanks in advance

1 Answer 1

1

Read the property, name outside the string concatenation block and then use it,

var name = value['name'];

and inside the string,

'......title="List of '+ name +'">......'
Sign up to request clarification or add additional context in comments.

1 Comment

Problem is in this part: onClick="showModal('+value+');" no '......title="List of '+ name +'">......' i need work with the array in showModal(arr) function, alert(arr['name']); is just an example.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.