1

I have a html button which I want to generate a report through a controller action, for example,

In my PaymentController.php

public function actionGenerateRI($date){...}

In my admin.php

<button type="button" onclick="generateRI()">Generate</button>

<script>
function generateRI(){
    var date = document.getElementById("month").value +"-"+ document.getElementById("year").value;
    //what should I write here to call the actionGenerateRI? 
}
</script>

How can I use my button to call the controller function AND pass the variable date?

P/S: They are both in the same model, in this case, Payment.

1 Answer 1

2

You can try this

var date = document.getElementById("month").value +"-"+ document.getElementById("year").value;

// If you are using path format
window.location.href= '<?php echo Yii::app()->createUrl('payment/generateRI'); ?>' + '/date/'+encodeURI(date);

// otherwise
window.location.href= '<?php echo Yii::app()->createUrl('payment/generateRI'); ?>' + '&date='+encodeURI(date);

// For more variables
window.location.href= '<?php echo Yii::app()->createUrl('payment/generateRI'); ?>' + '&date='+encodeURI(date)+'&variable2='+var2_value+'&variable3='+var3_value+'...;
Sign up to request clarification or add additional context in comments.

1 Comment

can I know what should I do if I want pass 2 or more variables?

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.