OnClick Action not declared

Hi, I have a view that displays a table from my database to the users. I added a search option so that the user can search this table. I’m totally new to this and I don’t know why nothing happens when I click the search button.

This is my code, I’m just trying to echo “ok” as a test:



    function myFunction()



            url: '<?php echo Yii::$app->request->baseUrl. '/supermarkets/sample' ?>',

           type: 'post',

           data: {searchname: $("#searchname").val()},

           success: function (data) {







use yii\helpers\Html;

use yii\widgets\LinkPager;

use app\views\supermarkets\search;





	Search by Name



<input type="text" value ="" name="searchname", id="searchname">

<button onclick="myFunction()">Search</button>

<h3> </h3>


$array = (array) $supermarkets;

function build_table($array){

    // start table

    $html = '<table class="altrowstable" id="alternatecolor">';

    // header row

    $html .= '<tr>';

    foreach($array[0] as $key=>$value){

            $html .= '<th>' . $key . '</th>';


    $html .= '</tr>';

    // data rows

    foreach( $array as $key=>$value){

        $html .= '<tr>';

        foreach($value as $key2=>$value2){

            $html .= '<td>' . $value2 . '</td>';


        $html .= '</tr>';


    // finish table and return it

    $html .= '</table>';

    return $html;


echo build_table($array);


<?= LinkPager::widget(['pagination' => $pagination]) ?>



namespace app\controllers;

use yii\web\Controller;

use yii\data\Pagination;

use app\models\Supermarkets;

use yii\data\ActiveDataProvider;

class SupermarketsController extends Controller


    public function actionIndex()


        $query = supermarkets::find();

        $pagination = new Pagination([

            'defaultPageSize' => 20,

            'totalCount' => $query->count(),


        $supermarkets = $query->orderBy('Name')





	 $dataProvider=new ActiveDataProvider('Supermarkets', array(








return $this->render('index', [


            'supermarkets' => $supermarkets,

            'pagination' => $pagination,




 public function actionSample(){



     echo "ok";


In the debug I noticed that actionSample isn’t being run. Could you please help me get through this?