1
I have to capture an event of click
in a radio button and pass its value in a PHP variable to be able to do a value calculation, I was not very successful, follow my code.
function Tipo_Frete() {
var frete = $("input[name='tipo_frete']:checked").val();
if (frete == "PAC") {
frete = 'pac'
}else if(frete == 'SEDEX'){
frete = 'sedex'
}
}
<?php $frete = "<script>document.write(frete)</script>";
What I need even now is for this variable to be accessed in view, without having to go through controller. I need a PHP variable to receive the value of button
marked, so in PHP I can do the calculation. How to make all this happen dynamically, without having to submit this along with the form, and handle everything on view?
You need to pass via post or get to php, so the "freight" variable does not exist in the server context. Use ajax to pass the variable "shipping" to php and capture using the global $_POST or $_GET, depending on how the request is made in ajax.
– user28595
You can use ajax or pass the url as @Diegofelipe said or pass an Hidden field via form Submit.
– rray
Thank you guys, but what I really need right now is for this variable to be accessed in the view, without having to go through the controller, I need a php variable to receive the value of the marked button, so in php I can do the calculation, all this needs to happen dynamically, understand, I can not submit this along with the form, I need to treat everything in the view.
– Aminadabe dos Santos da Silva
So the solution is to use ajax, so you make a request only when the radio button is changed.
– user28595
Okay, thanks a lot to everyone, we got through here, we used jquery and it worked, thanks a lot.
– Aminadabe dos Santos da Silva
If you can share your solution, it will help others with the same problem. Just post a!
– brasofilo